Eager loading

An entity in Entity Framework Core can be associated with other entities in a number of ways:

  • One-to-one relationship: Where two entities share a primary key
  • One-to-many: An entity has a collection of entities
  • Many-to-one: The inverse of one-to-many; an entity has a pointer to another entity

When querying for an entity, Entity Framework does not automatically bring the entities associated with it. This is actually a good thing: depending on how closely related the entities are, asking for one entity could bring with it the entire database!

This doesn't mean, of course, that we can't retrieve, on the same query, all the associated entities that we're interested in: this is called eager loading. In fact, in Entity Framework Core 1, this ...

Get Entity Framework Core Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.