Entity Framework
Entity Framework · 6 posts (all categories)
Entity Framework: eager and lazy loading
lazy loading:
- delaying load of data until we specifically request for it
- i.e. accessing
customer.Addressloads Address of a customer in the background via separate SQL query
- property needs to be public, virtual
- context.Configuration.ProxyCreationEnabled should be true
- context.Configuration.LazyLoadingEnabled should be true
- to disable lazy loading completely
Context.Configuration.LazyLoadingEnabled = false;
eager loading
- opposite of lazy loading
- loads related entities as part of the query
- done via
.Include()query
Further read:
Mapping collection of entities in EF with AutoMapper
In my last post I explained why is useful to add base entity class in EF. Today I will write how with use of this base class an AutoMapped map collection of data objects (i.e. DTOs to existing collection of entities).
Entity Framework and Base Entity class
Entity Framework does great job with taking care of entities changes and entities collection internally. And its uses almost plain POCO objects. Almost because collections of dependents data like in 1 to many tables relationship needs virtual keyword. Its understandable since EF needs to track what happens to collection. For instance lets have 2 tables: Customer and dependent Order. 
Ninject and Entity Framework
Last time I wrote about problem with testing Entity Framework in Visual Studio 2012. During working on this project I also encounter problems with configuration of Ninject to allow injecting Entity Framework classes from its Patterns extension. To be frankly this was not much a problem then lack of documentation. I just was forced to experiment with Ninject and new-thing-for-me Entity Framework Patterns extension.
Entity Framework Patterns extension and Unit Test in Visual Studio 2012
#Unit tests #reflection #NuGet #Ninject
Yesterday I was trying to make work simple test class in VS2012. I did not know what was wrong exactly. It was first project when I tried to glue together Entity Framework with repository pattern and Ninject as IoC container. Because of the fact that this was first time for solution like that I was sure that it is me, or rather source of my problem was indeed my code. But let’s not skip ahead.