LoadProperty in Entity Framework 5

I upgraded the first framework 4.3 entity database project to a new entity structure 5. Apparently now I am using DbContext instead of ObjectContext.

I replaced my old .edmx file with a new one. My old business code that previously used 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 accessible method in DbContext.

How can I get a strong typed load anyway?

I suggest that I could use

 context.Users.Include("Settings") 

but it is not strongly typed and subject to typos.

+7
source share
1 answer

You can also use the Include method with Lambda. don't forget the using statement, because this Include belongs to the DbExtension class:

 using System.Data.Entity; 

...

 context.Users.Include(u => u.Settings); 

here is some information about the include extension method: msdn info

+15
source

All Articles