I upgraded my entity framework 4.3 database first project to the new entity framework 5.
Apparently I'm now using DbContext instead of ObjectContext.
I've replaced my old .edmx file with a new one. My old business code, that was previously using my 4.3 .edmx file, now has a problem with code using the LoadProperty
method:
using (var context = new MyEntities())
{
Models.User user = context.Users.First(x => x.GUID == guid);
context.LoadProperty(user, o => o.Settings);
return user;
}
It seems that LoadProperty is not an available method in DbContext.
How can I can get strong typed loading anyway?
I suppose I could use
context.Users.Include("Settings")
but that is not strong typed and prone to typos.
All the developer has to do is install Microsoft. EntityFrameworkCore. Proxies package which will add all the required proxies needed to run Lazy Loading. After installing the package, the system will ask the developer to allow the installed proxies to access the databases and enable lazy loading.
3) Explicit Loading : This type of loading if force loading. This behaviour is like lazy loading but lazy loading disabled (in EF 6), it is still possible to lazily load related entities, but it must be done with an explicit call. We can implement it with use the Load() method to load related entities explicitly.
Lazy loading is the process whereby an entity or collection of entities is automatically loaded from the database the first time that a property referring to the entity/entities is accessed.
Eager loading means that the related data is loaded from the database as part of the initial query. Explicit loading means that the related data is explicitly loaded from the database at a later time.
You can use the Include method with Lambda too. don't forget the using statement, because this Include comes from the DbExtension class:
using System.Data.Entity;
...
context.Users.Include(u => u.Settings);
here is some info about the Include extension method: msdn info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With