Tutorial by Examples

Lazy loading is enabled by default. Lazy loading is achieved by creating derived proxy classes and overriding virtual navigation proeprties. Lazy loading occurs when property is accessed for the first time. int companyId = ...; Company company = context.Companies .First(m => m.Id == compan...
Eager loading lets you load all your needed entities at once. If you prefer to get all your entities to work on in one database call, then Eager loading is the way to go. It also lets you load multiple levels. You have two options to load related entities, you can choose either strongly typed or st...
After turning Lazy loading off you can lazily load entities by explicitly calling Load method for entries. Reference is used to load single navigation properties, whereas Collection is used to get collections. Company company = context.Companies.FirstOrDefault(); // Load founder context.Entry(com...
If one needs related data in a denormalized type, or e.g. only a subset of columns one can use projection queries. If there is no reason for using an extra type, there is the possibility to join the values into an anonymous type. var dbContext = new MyDbContext(); var denormalizedType = from compa...

Page 1 of 1