diff --git a/core/includes/database.inc b/core/includes/database.inc
index 26cdcc0..7b4ac87 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -476,6 +476,13 @@ function db_escape_field($field) {
  * Backslash is defined as escape character for LIKE patterns in
  * DatabaseCondition::mapConditionOperator().
  *
+ * Drupal considers LIKE case insensitive and the following is often used
+ * to tell the database that case insensitive equivalence is desired:
+ * @code
+ * db_select('users')
+ *  ->condition('name', db_like($name), 'LIKE')
+ * @endcode
+ *
  * @param $string
  *   The string to escape.
  *
diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index 2d53763..bd4fdd4 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -846,6 +846,13 @@ public function escapeAlias($field) {
    * Backslash is defined as escape character for LIKE patterns in
    * Drupal\Core\Database\Query\Condition::mapConditionOperator().
    *
+   * Drupal considers LIKE case insensitive and the following is often used
+   * to tell the database that case insensitive equivalence is desired:
+   * @code
+   * $this->connection->select('users')
+   * ->condition('name', $this->connection->escapeLike($name), 'LIKE')
+   * @encode
+   *
    * @param $string
    *   The string to escape.
    *
diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php
index cb131a9..54b7274 100644
--- a/core/lib/Drupal/Core/Database/Query/Select.php
+++ b/core/lib/Drupal/Core/Database/Query/Select.php
@@ -353,6 +353,10 @@ public function &getUnion() {
     return $this->union;
   }
 
+  public function escapeLike($string) {
+    return $this->connection->escapeLike($string);
+  }
+
   public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
     if (!isset($queryPlaceholder)) {
       $queryPlaceholder = $this;
@@ -784,4 +788,5 @@ public function __clone() {
       $this->union[$key]['query'] = clone($aggregate['query']);
     }
   }
+
 }
diff --git a/core/lib/Drupal/Core/Database/Query/SelectExtender.php b/core/lib/Drupal/Core/Database/Query/SelectExtender.php
index d60931d..0be678d 100644
--- a/core/lib/Drupal/Core/Database/Query/SelectExtender.php
+++ b/core/lib/Drupal/Core/Database/Query/SelectExtender.php
@@ -171,6 +171,10 @@ public function &getUnion() {
     return $this->query->getUnion();
   }
 
+  public function escapeLike($string) {
+    return $this->query->escapeLike($string);
+  }
+
   public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
     return $this->query->getArguments($queryPlaceholder);
   }
diff --git a/core/lib/Drupal/Core/Database/Query/SelectInterface.php b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
index 8e1c757..68505f1 100644
--- a/core/lib/Drupal/Core/Database/Query/SelectInterface.php
+++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
@@ -124,6 +124,18 @@ public function &getTables();
   public function &getUnion();
 
   /**
+   * Escapes characters that work as wildcard characters in a LIKE pattern.
+   *
+   * @param $string
+   *   The string to escape.
+   *
+   * @return
+   *   The escaped string.
+   * @see \Drupal\Core\Database\Connection::escapeLike
+   */
+  public function escapeLike($string);
+
+  /**
    * Compiles and returns an associative array of the arguments for this prepared statement.
    *
    * @param $queryPlaceholder
diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/CaseSensitiveStringItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/CaseSensitiveStringItem.php
new file mode 100644
index 0000000..38583d3
--- /dev/null
+++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/CaseSensitiveStringItem.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Entity\Plugin\DataType\CaseSensitiveStringItem.
+ */
+
+namespace Drupal\Core\Entity\Plugin\DataType;
+
+use Drupal\Core\TypedData\Annotation\DataType;
+use Drupal\Core\Annotation\Translation;
+use Drupal\Core\Entity\Field\FieldItemBase;
+
+/**
+ * Defines the 'case_sensitive_string_field' entity field item.
+ *
+ * @DataType(
+ *   id = "case_sensitive_string_field",
+ *   label = @Translation("Binary string field item"),
+ *   description = @Translation("An entity field containing a binary string (case sensitive) value."),
+ *   list_class = "\Drupal\Core\Entity\Field\Field"
+ * )
+ */
+class CaseSensitiveStringItem extends FieldItemBase {
+
+  /**
+   * Definitions of the contained properties.
+   *
+   * @see BinaryStringItem::getPropertyDefinitions()
+   *
+   * @var array
+   */
+  static $propertyDefinitions;
+
+  /**
+   * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions().
+   */
+  public function getPropertyDefinitions() {
+
+    if (!isset(static::$propertyDefinitions)) {
+      static::$propertyDefinitions['value'] = array(
+        'type' => 'string',
+        'label' => t('Text value'),
+        'case sensitive' => TRUE,
+      );
+    }
+    return static::$propertyDefinitions;
+  }
+}
diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
index c82a3da..aa9ead3 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
@@ -52,17 +52,35 @@ public function getEntityType();
    *   Possible values:
    *   - '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS',
    *     'ENDS_WITH': These operators expect $value to be a literal of the
-   *     same type as the column.
+   *     same type as the column. The case sensitivity of =, <>,
+   *     'STARTS_WITH', 'CONTAINS', 'ENDS_WITH' depends on the field
+   *     definition and can not be changed at query time. The case
+   *     (in)sensitive behavior of '>', '>=', '<', '<=' is only defined for
+   *     fields defined 'case sensitive'. Fields not defined as such might be
+   *     compared as case sensitive or case insensitive, depending on the
+   *     storage and should not be relied upon.
    *   - 'IN', 'NOT IN': These operators expect $value to be an array of
-   *     literals of the same type as the column.
+   *     literals of the same type as the column. When used with strings,
+   *     the case (in)sensitive behavior of these operators are only defined
+   *     for fields defined as 'case sensitive'. Fields not defined as such
+   *     might be compared as case sensitive or case insensitive, depending on
+   *     the storage and should not be relied upon. If case insensitive
+   *     comparison is important, use orConditionGroup() and a series of = or
+   *     <> conditions.
    *   - 'BETWEEN': This operator expects $value to be an array of two literals
-   *     of the same type as the column.
+   *     of the same type as the column. When used with strings, the case
+   *     (in)sensitive behavior of this operator is only defined for fields
+   *     defined as 'case sensitive'. Fields not defined as such might be
+   *     compared as case sensitive or case insensitive, depending on the
+   *     storage and should not be relied upon. There is no way to do a case
+   *     insensitive BETWEEN comparison.
    * @param $langcode
    *   Language code (optional).
    *
    * @return \Drupal\Core\Entity\Query\QueryInterface
-   * @see Drupal\Core\Entity\Query\andConditionGroup
-   * @see Drupal\Core\Entity\Query\orConditionGroup
+   * @see \Drupal\Core\Entity\Query\andConditionGroup
+   * @see \Drupal\Core\Entity\Query\orConditionGroup
+   * @see \Drupal\Core\Entity\Plugin\DataType\CaseSensitiveStringItem
    */
   public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL);
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index 19f6a3d..a253638 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -42,8 +42,8 @@ public function compile($conditionContainer) {
       }
       else {
         $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER';
-        $this->translateCondition($condition);
-        $field = $tables->addField($condition['field'], $type, $condition['langcode']);
+        $field = $tables->addField($condition, $type);
+        $this->translateCondition($condition, $sqlQuery);
         $conditionContainer->condition($field, $condition['value'], $condition['operator']);
       }
     }
@@ -68,23 +68,38 @@ public function notExists($field, $langcode = NULL) {
    *
    * @param array $condition
    */
-  protected function translateCondition(&$condition) {
+  protected function translateCondition(&$condition, SelectInterface $sqlQuery) {
+    // There is nothing we can do for IN ().
+    if (is_array($condition['value'])) {
+      return;
+    }
     switch ($condition['operator']) {
+      case '=':
+        if (!$condition['case sensitive']) {
+          $condition['value'] = $sqlQuery->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (!$condition['case sensitive']) {
+          $condition['value'] = $sqlQuery->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $sqlQuery->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $sqlQuery->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $sqlQuery->escapeLike($condition['value']);
         $condition['operator'] = 'LIKE';
         break;
-
     }
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
index cd83691..8abea24 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Entity\Query\Sql;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Query\SelectInterface;
 use Drupal\Core\Entity\Query\ConditionAggregateBase;
 use Drupal\Core\Entity\Query\ConditionAggregateInterface;
@@ -37,8 +38,8 @@ public function compile($conditionContainer) {
       }
       else {
         $type = ((strtoupper($this->conjunction) == 'OR') || ($condition['operator'] == 'IS NULL')) ? 'LEFT' : 'INNER';
-        $this->translateCondition($condition);
-        $field = $tables->addField($condition['field'], $type, $condition['langcode']);
+        $field = $tables->addField($condition, $type);
+        $this->translateCondition($condition, $sql_query);
         $function = $condition['function'];
         $placeholder = ':db_placeholder_' . $conditionContainer->nextPlaceholder();
         $conditionContainer->having("$function($field) {$condition['operator']} $placeholder", array($placeholder => $condition['value']));
@@ -64,22 +65,36 @@ public function notExists($field, $function, $langcode = NULL) {
    * Translates the string operators to SQL equivalents.
    *
    * @param array $condition
-   *   An associative array containing the following keys:
-   *     - value: The value to filter by
-   *     - operator: The operator to use for comparison, for example "=".
    */
-  protected function translateCondition(&$condition) {
+  protected function translateCondition(&$condition, SelectInterface $sqlQuery) {
+    if (is_array($condition['value'])) {
+      return;
+    }
     switch ($condition['operator']) {
+      case '=':
+        if (!$condition['binary']) {
+          $condition['value'] = $sqlQuery->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (!$condition['binary']) {
+          $condition['value'] = $sqlQuery->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $sqlQuery->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $sqlQuery->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $sqlQuery->escapeLike($condition['value']);
         $condition['operator'] = 'LIKE';
         break;
     }
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
index debc403..3cf753b 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -290,7 +290,8 @@ protected function getSqlField($field, $langcode) {
       return $base_property;
     }
     else {
-      return $this->tables->addField($field, 'LEFT', $langcode);
+      $definition = array('field' => $field, 'langcode' => $langcode);
+      return $this->tables->addField($definition, 'LEFT');
     }
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
index a3d8e0a..9200758 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -52,7 +52,9 @@ public function __construct(SelectInterface $sql_query) {
   /**
    * {@inheritdoc}
    */
-  public function addField($field, $type, $langcode) {
+  public function addField(&$field_definition, $type) {
+    $field = $field_definition['field'];
+    $langcode = $field_definition['langcode'];
     $entity_type = $this->sqlQuery->getMetaData('entity_type');
     $age = $this->sqlQuery->getMetaData('age');
     // This variable ensures grouping works correctly. For example:
@@ -98,9 +100,11 @@ public function addField($field, $type, $langcode) {
       // id:$field_id so check that first.
       if (substr($specifier, 0, 3) == 'id:') {
         $field = field_info_field_by_id(substr($specifier, 3));
+        $need_entity = FALSE;
       }
       elseif (isset($field_map[$specifier])) {
         $field = field_info_field($specifier);
+        $need_entity = TRUE;
       }
       else {
         $field = FALSE;
@@ -109,6 +113,20 @@ public function addField($field, $type, $langcode) {
       if ($field) {
         // Find the field column.
         $column = FALSE;
+        if ($need_entity) {
+          // Get the field definitions form a mocked entity.
+          $values = array();
+          $field_name = $field->getFieldName();
+          // If there are bundles, pick one.
+          if (!empty($entity_info['entity_keys']['bundle'])) {
+            $values[$entity_info['entity_keys']['bundle']] = reset($field_map[$field_name]['bundles'][$entity_type]);
+          }
+          $entity = entity_create($entity_type, $values);
+          $propertyDefinitions = $entity->getNGEntity()->{$field['field_name']}->getPropertyDefinitions();
+        }
+        else {
+          $propertyDefinitions = array();
+        }
         if ($key < $count) {
           $next = $specifiers[$key + 1];
           // Is this a field column?
@@ -128,10 +146,6 @@ public function addField($field, $type, $langcode) {
           if ($key < $count) {
             $relationship_specifier = $specifiers[$key + 1];
 
-            // Get the field definitions form a mocked entity.
-            $entity = entity_create($entity_type, array());
-            $propertyDefinitions = $entity->{$field['field_name']}->getPropertyDefinitions();
-
             // If the column is not yet known, ie. the
             // $node->field_image->entity case then use first property as
             // column, i.e. target_id or fid.
@@ -150,12 +164,13 @@ public function addField($field, $type, $langcode) {
         }
         $table = $this->ensureFieldTable($index_prefix, $field, $type, $langcode, $base_table, $entity_id_field, $field_id_field);
         $sql_column = _field_sql_storage_columnname($field['field_name'], $column);
+        $field_definition['case sensitive'] = !empty($propertyDefinitions[$column]['case sensitive']);
       }
       // This is an entity property (non-configurable field).
       else {
         // ensureEntityTable() decides whether an entity property will be
         // queried from the data table or the base table based on where it
-        // finds the property first. The data table is prefered, which is why
+        // finds the property first. The data table is preferred, which is why
         // it gets added before the base table.
         $entity_tables = array();
         if (isset($entity_info['data_table'])) {
@@ -164,7 +179,7 @@ public function addField($field, $type, $langcode) {
         }
         $entity_tables[$entity_info['base_table']] = drupal_get_schema($entity_info['base_table']);
         $sql_column = $specifier;
-        $table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
+        $table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables, $field_definition);
       }
       // If there are more specifiers to come, it's a relationship.
       if ($key < $count) {
@@ -211,9 +226,10 @@ public function addField($field, $type, $langcode) {
    * @return string
    * @throws \Drupal\Core\Entity\Query\QueryException
    */
-  protected function ensureEntityTable($index_prefix, $property, $type, $langcode, $base_table, $id_field, $entity_tables) {
+  protected function ensureEntityTable($index_prefix, $property, $type, $langcode, $base_table, $id_field, $entity_tables, &$field_definition) {
     foreach ($entity_tables as $table => $schema) {
       if (isset($schema['fields'][$property])) {
+        $field_definition['case sensitive'] = !empty($schema['fields'][$property]['binary']);
         if (!isset($this->entityTables[$index_prefix . $table])) {
           $this->entityTables[$index_prefix . $table] = $this->addJoin($type, $table, "%alias.$id_field = $base_table.$id_field", $langcode);
         }
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
index 50e5655..fb47dc8 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
@@ -15,13 +15,14 @@
   /**
    * Adds a field to a database query.
    *
-   * @param string $field
-   *   If it contains a dot, then field name dot field column. If it doesn't
-   *   then entity property name.
+   * @param array &$field_definition
+   *   An array with two keys:
+   *   - field: If it contains a dot, then field name dot field column. If it
+   *    doesn't then entity property name. The function will set the binary
+   *    key in the array to TRUE if the field is a binary field.
+   *   - langcode: The language code the field values are to be shown in.
    * @param string $type
    *   Join type, can either be INNER or LEFT.
-   * @param $langcode
-   *   The language code the field values are to be shown in.
    *
    * @throws \Drupal\Core\Entity\Query\QueryException
    *   If $field specifies an invalid relationship.
@@ -31,6 +32,6 @@
    *   and the appropriate SQL column as passed in. This allows the direct use
    *   of this in a query for a condition or sort.
    */
-  public function addField($field, $type, $langcode);
+  public function addField(&$field_definition, $type);
 
 }
diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php
index f3167a6..d2fe0a5 100644
--- a/core/modules/file/lib/Drupal/file/FileStorageController.php
+++ b/core/modules/file/lib/Drupal/file/FileStorageController.php
@@ -74,7 +74,7 @@ public function baseFieldDefinitions() {
     $properties['uri'] = array(
       'label' => t('URI'),
       'description' => t('The URI to access the file (either local or remote).'),
-      'type' => 'string_field',
+      'type' => 'case_sensitive_string_field',
     );
     $properties['filemime'] = array(
       'label' => t('File MIME type'),
