Take the 2-minute tour ×

I am using EF4, and I using the System.Data.Entity dll in my class. However, I can't see the load method of my navigation property of my entity.

How can I access to this method?

What I am doing is create e 4.0 project of .NET, create my edmx from a database, right click in the model edmx and I generate a DBContext.

However, I can access to the local property of my context, that I think that is a feature of EF4.

Thanks. Daimroc.

share|improve this question
Isn't each controller action in essence a load method? –  Sam I am Nov 13 '12 at 17:35
add comment

2 Answers

up vote 4 down vote accepted

For the DbContext approach, the IsLoaded property and Load method have been moved:

   .Collection(entity => entity.NavigationProperty)

   .Collection(entity => entity.NavigationProperty)
share|improve this answer
add comment

When you write the query (all this also works with lambda syntax as well btw)

From a in context.EntitySet.Include("Navigation Property NAme")
select a

and all will be there ;) .. or more to the point the navigation properties will be populated.

can be wierd with lots of joins though

you can also

From a in context.EntitySet.Include("Navigation1.Navigation2.Navigation2")
    select a

where navigation1 and SomeOtherNavigation are navigation properties on the entity set

Failing that you can turn on lazy loading in the context. But its evil imo. Also it doesnt really scale well when you go for an SOA approach as you need to include prior to knowing about the lazy load in your repository.

Ie you run the query in your repository, send stuff over the service and then want the navigation properties in the front end ... by which time its too late to lazy load ... EG you are using a wcf service that doesn't use data services.

Important to note that you ahve to use Include on the EntitySet, it is not on an IQueryable<>.

A real example:

   var csg = from ucsg in c.UserCarShareGroups.Include("UserCarShareGroups.User.UserVehicles")
                      where ucsg.User.UserName.ToLower() == userName.ToLower()
                      && ucsg.CarShareGroup.Carpark.Name.ToLower().Equals(carparkName.ToLower())
                      && ucsg.DeletedBy == null
                      select ucsg.CarShareGroup;

(the database has case sensitive collation for some reason)

An alternate approach (and maybe more relevant is here) Entity Framework - Trouble with .Load()

However I like doing it the way I said because it is explicit and I know exactly what is being pulled out. Especially when dealing with large datasets.

An answer to a question that combines my concerns with Load() is here: Entity Framework 4 load and include combine

share|improve this answer
FWIW, Include and Load are completely different features. Include eager loads. Load pulls in related data after the fact. So be careful about suggesting to use Include as an answer to a question about "where is the load method". If it's helpful, here's an article I wrote about the specific differences along with guidance for when to use which one: msdn.microsoft.com/en-us/magazine/… –  Julie Lerman Nov 13 '12 at 18:19
Nice article, thanks. I seem to be out of date on entity framework :D –  John Nicholas Nov 14 '12 at 10:10
add comment

Your Answer


