Eager loading refers to the process in which a query, when executed on a particular type of an entity, also loads the related entities at the same time. Lazy loading and eager loading are used for loading related entities that pertain to an entity. In the former case, the related entities are not loaded automatically along with its parent entity unless they are requested. In the latter case, the related entities are loaded automatically along with the parent entity.
To achieve eager loading in Entity Framework, you need to make use of the Include
method.
Here is an example:
using (var context = new SecurityContext()) { // Load all user types and the related users var data = context.UserTypes .Include(u => u.Users) .ToList(); // Load one user type and its related users var data = context.UserTypes .Where(u => u.UserType == "ADUser") .Include...