Including related entities

Okay, so you’ve executed a query that loads all your recipes, and you know that you want to look at recipe ingredients. (And you know that you don’t want to make several bazillion trips to the server.) There are two possible situations: You might want to look at the ingredients of all the recipes, or you might want to only look at the ingredients of a selected recipe. The Entity Framework supports both scenarios. To include all the related entities in your query, you use the Include() method:

The Include() method allows you to load related entities when the query is executed:

Image

You can include multiple levels of relationships ...

Get Fluent Entity Framework 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.