Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.1, can't find Load() method?

Ok, I'm about to smash my keyboard with a hammer over this. I decided to play with EF this weekend and I started a project in 4.0. I find out 4.1 is out so I download and install the package.

Imagine my surprise when I go to use the Load() method in the dbExtensions and it can't find it. So I add a reference to the EntityFramework binary that the installer created, remove the System.Data.Entity reference from the project, rebuild, and it says

"The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."

I tried to regenerate my model, I tried removing things, I tried directly referencing the 4.1 via usings. Nothing works.

I'm obviously missing something basic. How in the heck do I tell visual studio to use the 4.1 framework??!!

like image 543
Eric Avatar asked Apr 24 '11 19:04

Eric


People also ask

How you can Load related entities in EF?

Entity Framework supports three ways to load related data - eager loading, lazy loading and explicit loading. The techniques shown in this topic apply equally to models created with Code First and the EF Designer.

How do I use Find in Entity Framework?

The Find method on DbSet uses the primary key value to attempt to find an entity tracked by the context. If the entity is not found in the context then a query will be sent to the database to find the entity there. Null is returned if the entity is not found in the context or in the database.

What is explicit loading in EF?

Explicit Loading is a technique we query and load the related entities with an explicit call. Explicit loading works very similar to Lazy Loading, but the loading of the related entities happens only after an explicit call. The loading only when we invoke the Load method of the related entity's DBEntityEntry object.

What is Eager loading in EF core?

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.


1 Answers

I managed to find the missing .Load() function by adding the following:

using System.Data.Entity;
like image 160
Asif Avatar answered Sep 28 '22 01:09

Asif