diff --git a/core/includes/database.inc b/core/includes/database.inc
index 6d5318b..ac68f88 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -527,6 +527,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 7cbe167..5c26174 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -844,6 +844,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 3c687da..d369b64 100644
--- a/core/lib/Drupal/Core/Database/Query/Select.php
+++ b/core/lib/Drupal/Core/Database/Query/Select.php
@@ -501,6 +501,13 @@ public function &getUnion() {
   /**
    * {@inheritdoc}
    */
+  public function escapeLike($string) {
+    return $this->connection->escapeLike($string);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
     if (!isset($queryPlaceholder)) {
       $queryPlaceholder = $this;
@@ -984,4 +991,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 9a378d2..3a275d2 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 b784610..0d98285 100644
--- a/core/lib/Drupal/Core/Database/Query/SelectInterface.php
+++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
@@ -126,6 +126,19 @@ public function &getTables();
   public function &getUnion();
 
   /**
+   * Escapes characters that work as wildcard characters in a LIKE pattern.
+   *
+   * @param $string
+   *   The string to escape.
+   *
+   * @return string
+   *   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/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
index 5a34cac..4ee0cae 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
@@ -54,7 +54,7 @@ public function getEntityTypeId();
    *   same delta within that field.
    * @param $value
    *   The value for $field. In most cases, this is a scalar and it's treated as
-   *   case-insensitive. For more complex options, it is an array. The meaning
+   *   case-insensitive. For more complex operators, it is an array. The meaning
    *   of each element in the array is dependent on $operator.
    * @param $operator
    *   Possible values:
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index 1067db3..b6396465 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -33,20 +33,20 @@ public function compile($conditionContainer) {
     // SQL query object is only necessary to pass to Query::addField() so it
     // can join tables as necessary. On the other hand, conditions need to be
     // added to the $conditionContainer object to keep grouping.
-    $sqlQuery = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
-    $tables = $this->query->getTables($sqlQuery);
+    $sql_query = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
+    $tables = $this->query->getTables($sql_query);
     foreach ($this->conditions as $condition) {
       if ($condition['field'] instanceOf ConditionInterface) {
-        $sqlCondition = new SqlCondition($condition['field']->getConjunction());
+        $sql_condition = new SqlCondition($condition['field']->getConjunction());
         // Add the SQL query to the object before calling this method again.
-        $sqlCondition->sqlQuery = $sqlQuery;
-        $condition['field']->compile($sqlCondition);
-        $sqlQuery->condition($sqlCondition);
+        $sql_condition->sqlQuery = $sql_query;
+        $condition['field']->compile($sql_condition);
+        $sql_query->condition($sql_condition);
       }
       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);
         $conditionContainer->condition($field, $condition['value'], $condition['operator']);
       }
     }
@@ -71,23 +71,38 @@ public function notExists($field, $langcode = NULL) {
    *
    * @param array $condition
    */
-  protected function translateCondition(&$condition) {
+  protected function translateCondition(&$condition, SelectInterface $sql_query) {
+    // There is nothing we can do for IN ().
+    if (is_array($condition['value'])) {
+      return;
+    }
     switch ($condition['operator']) {
+      case '=':
+        if (empty($condition['case sensitive'])) {
+          $condition['value'] = $sql_query->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (empty($condition['case sensitive'])) {
+          $condition['value'] = $sql_query->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $sql_query->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $sql_query->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $sql_query->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..520348c 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
@@ -10,6 +10,7 @@
 use Drupal\Core\Database\Query\SelectInterface;
 use Drupal\Core\Entity\Query\ConditionAggregateBase;
 use Drupal\Core\Entity\Query\ConditionAggregateInterface;
+use Drupal\Core\Database\Query\Condition as SqlCondition;
 
 /**
  * Defines the aggregate condition for sql based storage.
@@ -29,7 +30,7 @@ public function compile($conditionContainer) {
     $tables = new Tables($sql_query);
     foreach ($this->conditions as $condition) {
       if ($condition['field'] instanceOf ConditionAggregateInterface) {
-        $sql_condition = new Condition($condition['field']->getConjunction());
+        $sql_condition = new SqlCondition($condition['field']->getConjunction());
         // Add the SQL query to the object before calling this method again.
         $sql_condition->sqlQuery = $sql_query;
         $condition['field']->compile($sql_condition);
@@ -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,37 @@ 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 $sql_query) {
+    // There is nothing we can do for IN ().
+    if (is_array($condition['value'])) {
+      return;
+    }
     switch ($condition['operator']) {
+      case '=':
+        if (empty($condition['case sensitive'])) {
+          $condition['value'] = $sql_query->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (empty($condition['case sensitive'])) {
+          $condition['value'] = $sql_query->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $sql_query->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $sql_query->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $sql_query->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 cf8eb39..97904d3 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -277,7 +277,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 b1c1a54..3dce698 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -61,8 +61,10 @@ public function __construct(SelectInterface $sql_query) {
   /**
    * {@inheritdoc}
    */
-  public function addField($field, $type, $langcode) {
+   public function addField(&$field_definition, $type) {
     $entity_type_id = $this->sqlQuery->getMetaData('entity_type');
+    $field = $field_definition['field'];
+    $langcode = $field_definition['langcode'];
     $age = $this->sqlQuery->getMetaData('age');
     // This variable ensures grouping works correctly. For example:
     // ->condition('tags', 2, '>')
@@ -144,6 +146,9 @@ public function addField($field, $type, $langcode) {
         }
         $table = $this->ensureFieldTable($index_prefix, $field_storage, $type, $langcode, $base_table, $entity_id_field, $field_id_field);
         $sql_column = $table_mapping->getFieldColumnName($field_storage, $column);
+        if (isset($propertyDefinitions[$column])) {
+          $field_definition['case sensitive'] = $propertyDefinitions[$column]->getSetting('case_sensitive');
+        }
       }
       // This is an entity base field (non-configurable field).
       else {
@@ -159,7 +164,7 @@ public function addField($field, $type, $langcode) {
         $entity_base_table = $entity_type->getBaseTable();
         $entity_tables[$entity_base_table] = $this->getTableMapping($entity_base_table, $entity_type_id);
         $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 ($field_storage && $key < $count) {
@@ -198,9 +203,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 => $mapping) {
       if (isset($mapping[$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..c6f0108 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/src/Entity/File.php b/core/modules/file/src/Entity/File.php
index b21a182..d1ae4f6 100644
--- a/core/modules/file/src/Entity/File.php
+++ b/core/modules/file/src/Entity/File.php
@@ -260,7 +260,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
     $fields['uri'] = BaseFieldDefinition::create('uri')
       ->setLabel(t('URI'))
       ->setDescription(t('The URI to access the file (either local or remote).'))
-      ->setSetting('max_length', 255);
+      ->setSetting('max_length', 255)
+      ->setSetting('case_sensitive', TRUE);
 
     $fields['filemime'] = BaseFieldDefinition::create('string')
       ->setLabel(t('File MIME type'))
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php
index 3fde79b..0f0ab95 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php
@@ -85,7 +85,7 @@ public function testFieldInstanceSettings() {
     // Test a text field.
     $field = entity_load('field_config', 'node.story.field_test');
     $this->assertEqual($field->label(), 'Text Field');
-    $expected = array('max_length' => 255);
+    $expected = array('max_length' => 255, 'case_sensitive' => FALSE);
     $this->assertEqual($field->getSettings(), $expected);
     $this->assertEqual('text for default value', $entity->field_test->value);
 
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
index 85ef644..04e9b82 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
@@ -46,7 +46,7 @@ public function testFields() {
     // Text field.
     /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
     $field_storage = entity_load('field_storage_config', 'node.field_test');
-    $expected = array('max_length' => 255);
+    $expected = array('max_length' => 255, 'case_sensitive' => FALSE);
     $this->assertEqual($field_storage->type, "text",  t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->type)));
     $this->assertEqual($field_storage->status(), TRUE, "Status is TRUE");
     $this->assertEqual($field_storage->settings, $expected, "Field type text settings are correct");
diff --git a/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php b/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
index 1df6c88..24ee9d5 100644
--- a/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
@@ -45,7 +45,7 @@ class EntityQueryAggregateTest extends EntityUnitTestBase {
   protected function setUp() {
     parent::setUp();
 
-    $this->entityStorage = $this->container->get('entity.manager')->getStorage('entity_test');
+    $this->entityStorage = $this->entityManager->getStorage('entity_test');
     $this->factory = $this->container->get('entity.query');
 
     // Add some fieldapi fields to be used in the test.
diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php
index 2585177..fcaa739 100644
--- a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php
+++ b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php
@@ -29,6 +29,7 @@ class TextItem extends TextItemBase {
   public static function defaultStorageSettings() {
     return array(
       'max_length' => 255,
+      'case_sensitive' => FALSE,
     ) + parent::defaultStorageSettings();
   }
 
@@ -42,6 +43,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
           'type' => 'varchar',
           'length' => $field_definition->getSetting('max_length'),
           'not null' => FALSE,
+          'binary' => $field_definition->getSetting('case_sensitive'),
         ),
         'format' => array(
           'type' => 'varchar',
@@ -91,6 +93,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
       '#min' => 1,
       '#disabled' => $has_data,
     );
+    $element += parent::storageSettingsForm($form, $form_state, $has_data);
 
     return $element;
   }
diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php
index bf1054f..98ad050 100644
--- a/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php
+++ b/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php
@@ -29,7 +29,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
     return array(
       'columns' => array(
         'value' => array(
-          'type' => 'text',
+          'type' => $field_definition->getSetting('case_sensitive') ? 'blob' : 'text',
           'size' => 'big',
           'not null' => FALSE,
         ),
diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php
index 92185ab..e4705ec 100644
--- a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php
+++ b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php
@@ -59,12 +59,12 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
     return array(
       'columns' => array(
         'value' => array(
-          'type' => 'text',
+          'type' => $field_definition->getSetting('case_sensitive') ? 'blob' : 'text',
           'size' => 'big',
           'not null' => FALSE,
         ),
         'summary' => array(
-          'type' => 'text',
+          'type' => $field_definition->getSetting('case_sensitive') ? 'blob' : 'text',
           'size' => 'big',
           'not null' => FALSE,
         ),
