diff -u b/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php --- b/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -1246,7 +1246,7 @@ ->fetchField(); // Log the count in a table that records this statistic for deleted entities. - \Drupal::database()->merge('example_deleted_entity_statistics') + $connection->merge('example_deleted_entity_statistics') ->key(['type' => $type, 'id' => $id]) ->fields(['count' => $count]) ->execute();