Depending on the type of entity, it is either nid/vid/uid and possibly other. It is nice to have an ->id() method which allows you to work with data in an uniform fashion without relying on those details, but there are quite some use-cases, where I am running into troubles.
Just an example, getting list of revision ids for an generic entity seems not possible without knowing the name of the id-field.
$entityTypeId = $entity->getEntityTypeId(); $entityId = $entity->id(); $typeStorage = \Drupal::entityTypeManager()->getStorage($entityTypeId); $query = $typeStorage->getQuery(); $query->allRevisions(); $query->condition("??????", $entityId);
$id_field = $entity->getKey('id');