diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 973bccb..ac6cb86 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -261,9 +261,7 @@ function comment_menu_alter(&$items) {
  * Returns a menu title which includes the number of unapproved comments.
  */
 function comment_count_unpublished() {
-  $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
-    ':status' => COMMENT_NOT_PUBLISHED,
-  ))->fetchField();
+  $count = \Drupal::entityQuery('comment')->condition('status', COMMENT_NOT_PUBLISHED)->count()->execute();
   return t('Unapproved comments (@count)', array('@count' => $count));
 }
 
@@ -1167,7 +1165,7 @@ function comment_node_insert(EntityInterface $node) {
  * Implements hook_node_predelete().
  */
 function comment_node_predelete(EntityInterface $node) {
-  $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->id()))->fetchCol();
+  $cids = \Drupal::entityQuery('comment')->condition('nid', $node->id)->execute();
   entity_delete_multiple('comment', $cids);
   db_delete('node_comment_statistics')
     ->condition('nid', $node->id())
@@ -1329,11 +1327,12 @@ function comment_num_new($nid, $timestamp = 0) {
     $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT);
 
     // Use the timestamp to retrieve the number of new comments.
-    return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND created > :timestamp AND status = :status', array(
-      ':nid' => $nid,
-      ':timestamp' => $timestamp,
-      ':status' => COMMENT_PUBLISHED,
-      ))->fetchField();
+    return \Drupal::entityQuery('comment')
+      ->condition('nid', $nid)
+      ->condition('timestamp', $timestamp, '>')
+      ->condition('status', COMMENT_PUBLISHED)
+      ->count()
+      ->execute();
   }
   else {
     return FALSE;
diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php
index 59d27b5..c1ddd4b 100644
--- a/core/modules/node/node.api.php
+++ b/core/modules/node/node.api.php
@@ -701,7 +701,11 @@ function hook_node_update(\Drupal\Core\Entity\EntityInterface $node) {
  */
 function hook_node_update_index(\Drupal\Core\Entity\EntityInterface $node, $langcode) {
   $text = '';
-  $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->id(), ':status' => COMMENT_PUBLISHED));
+  $cids = \Drupal::entityQuery('comment')
+    ->condition('nid', $node->id())
+    ->condition('status', COMMENT_PUBLISHED)
+    ->execute();
+  $comments = \Drupal::entityManager()->getStorageController('comment')->loadMultiple($cids);
   foreach ($comments as $comment) {
     $text .= '<h2>' . check_plain($comment->subject->value) . '</h2>' . $comment->comment_body->processed;
   }
diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module
index 80b0d5a..b0b9385 100644
--- a/core/modules/tracker/tracker.module
+++ b/core/modules/tracker/tracker.module
@@ -317,12 +317,16 @@ function _tracker_calculate_changed($nid) {
   // @todo This should be actually filtering on the desired language and just
   //   fall back to the default language.
   $changed = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1 ORDER BY changed DESC', array(':nid' => $nid), array('target' => 'slave'))->fetchField();
-  $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array(
-    ':nid' => $nid,
-    ':status' => COMMENT_PUBLISHED,
-  ), array('target' => 'slave'))->fetchObject();
-  if ($latest_comment && $latest_comment->changed > $changed) {
-    $changed = $latest_comment->changed;
+  $latest_comment_cid = \Drupal::entityQuery('comment')
+    ->condition('nid', $nid)
+    ->condition('status', COMMENT_PUBLISHED)
+    ->execute();
+
+  if ($latest_comment_cid) {
+    $latest_comment = \Drupal::entityManager()->getStorageController('comment')->load(reset($latest_comment_cid));
+    if ($latest_comment && $latest_comment->changed > $changed) {
+      $changed = $latest_comment->changed;
+    }
   }
   return $changed;
 }
@@ -354,11 +358,13 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
     // Comments are a second reason to keep the user's subscription.
     if (!$keep_subscription) {
       // Check if the user has commented at least once on the given nid.
-      $keep_subscription = db_query_range('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND uid = :uid AND status = :status', 0, 1, array(
-        ':nid' => $nid,
-        ':uid' => $uid,
-        ':status' => COMMENT_PUBLISHED,
-      ))->fetchField();
+      $keep_subscription = \Drupal::entityQuery('comment')
+        ->condition('status', COMMENT_PUBLISHED)
+        ->condition('uid', $uid)
+        ->condition('nid', $nid)
+        ->range(0, 1)
+        ->count()
+        ->execute();
     }
 
     // If we haven't found a reason to keep the user's subscription, delete it.
