Why is my update query OK for the database but the page shows the wrong value? I have 2 custom content entities created with Drupal Console (drupal generate:entity:content): 'person' and 'member'.
They are linked (1 member &lt;-> n persons) by a field named 'member_id' in 'person'.
If a person is set with 'iscontact' = true, the other persons related to the same member should have 'iscontact' = false.  

In the PersonForm.php, I have this code.

public function save(array $form, FormStateInterface $form_state) {
  $entity = $this-&gt;entity;

  if ($entity-&gt;get('iscontact')) {

    $member_id = $entity-&gt;get('member_id')-&gt;getString();
    $iId = $entity-&gt;get('id')-&gt;getString();
    $database = \Drupal::database();
    $query = $database-&gt;select('person', 'ap');
    $query-&gt;fields('ap', ['id', 'member_id'])
      -&gt;condition('id', $iId, '&lt;&gt;')
      -&gt;condition('member_id', $member_id, '=');
    $results = $query-&gt;execute();

    foreach ($results as $key=&gt;$result) {
      $numberofrowsaffected = $database-&gt;update('person')
        -&gt;fields(['iscontact' =&gt; 0,])
        -&gt;condition('id', $result-&gt;id)
        -&gt;execute();
    }
  }

  $status = parent::save($form, $form_state);

  switch ($status) {
    case SAVED_NEW:
      drupal_set_message($this-&gt;t('La personne « %label » a été ajoutée.', [
        '%label' =&gt; $entity-&gt;label(),
      ]));
      break;
    default:
      drupal_set_message($this-&gt;t('La personne « %label » a été modifiée.', [
        '%label' =&gt; $entity-&gt;label(),
      ]));
  }
  $form_state-&gt;setRedirect('entity.person.canonical', ['person' =&gt; $entity-&gt;id()]);
}


When I execute this, the table 'person' in the database is correctly updated, but in the page the previous person is still seen as having 'iscontact' = 1.
It's incorrect until I clear the cache. 
What am I doing wrong?
I replaced  

foreach ($results as $key=&gt;$result) {
  $numberofrowsaffected = $database-&gt;update('person')
    -&gt;fields(['iscontact' =&gt; 0,])
    -&gt;condition('id', $result-&gt;id)
    -&gt;execute();
}


by  

  $storage = \Drupal::entityTypeManager()-&gt;getStorage('person');
  foreach ($results as $key=&gt;$result) {
    $person = $storage-&gt;load($result-&gt;id);
    $person-&gt;iscontact = 0;
    $person-&gt;save();


And it works!