So far we have looked at accessing data for a single type of entity
and everything has been about
Destinations. But if we were writing a real
application, we would probably want to know something about the
Lodging that is available at each
Destination. If we want to access the
Lodgings associated with a
Destination, that means working with related
You’ll need to pull related data into memory so that we can look at it. There are three approaches you can use to load related data: lazily, eagerly, or explicitly. While they may achieve the same end result, there are some differences between each approach that can have a significant impact on performance. This isn’t a one-time decision either. Different approaches may be better at different times. This section will walk through the three available options and help you work out which one is best for you in different situations.
The “Demystifying Entity Framework Strategies: Loading Related Data” MSDN article gives a detailed look at the pros and cons of the different strategies and some pointers on choosing the right strategy for you.
Lazy loading related data is the most transparent to your
application and involves letting Entity Framework automatically retrieve
the related data for you when you try to access it. For example, you may
have the Grand Canyon destination loaded. If you then use the
Lodgings property of this
Destination, Entity Framework will automatically send a query to the database ...