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, C开发者_JAVA技巧ulture=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??!!
I managed to find the missing .Load() function by adding the following:
using System.Data.Entity;
Entity Framework 4.1 is not separate version. It still needs Entity Framework 4.0 and its assembly so yu can't remove System.Data.Entity.dll from your references. Also EFv4.1 is mainly about new DbContext API so unless you are going to swith from Entity objects to POCOs and DbContext
you will not get any advantage by referencing EntityFramework.dll (except strongly typed Include
on IQueryable
).
Add a Reference to System.Data.Entity.dll
from either:
GAC (.Net tab in add reference dialog)
or
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Entity.dll
I got the same issue, and still don't know the root cause.
Finally I use some alternative solution:
var query = from d ...
query.Load();
or
(DbSet)context.myentity).Load();
Please try.
Ladislav's post is accurate. To add a little more detail, this ADO.Net team blog post explains how to correctly replace the code generation in an EF 4.0 project with EF 4.1.
However, I have a similar issue after upgrading to 4.1 and using DbContext (including some other features) I don't have a .Load() method either. I think you were in the same place I am before you started (unnecessarily) messing with references.
Check out the link above, let me know if it helps, and if you find a solution for the missing .Load() function be sure and let us know.
精彩评论