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.
You can use the Include method with Lambda too.
don’t forget the using statement, because this Include comes from the DbExtension class:
…
here is some info about the Include extension method: msdn info