问题
I'm using entity framework 5 and have two Visual Studio 2010 solutions. One is a small test solution with one project and one is a much larger solution with multiple projects where I'm doing the actual business application.
The entities in the smaller solution have both the .Load() method and the .Local property.
The entities in the larger solution have neither.
I've referenced both system.data.entity and EntityFramework in the projects.
I've compared the two solutions and can't figure out what is missing in the large one. Any pointers in what direction to look next would be appreciated.
回答1:
Prompted by the comment from Pawel, I discovered that the smaller solution
is based on DbContext which gives me the .Load()
method and the .Local
property.
To switch the larger solution
to DbContext
, I followed these steps from this webpage http://msdn.microsoft.com/en-US/data/jj206878
Next, we need to swap our model to generate code that makes use of the DbContext API, which was introduced in later versions of Entity Framework.
Right-click on an empty spot of your model in the EF Designer and select Add Code Generation Item…
Select Online Templates from the left menu and search for DbContext
Select the EF 5.x DbContext Generator for C#, enter "YourChoiceOfName" as the name and click Add
I now have the .Local
property and I suspect the .Load()
method is available as well although I haven't used it yet.
来源:https://stackoverflow.com/questions/13167563/entity-framework-5-0-load-method-and-local-property-are-missing-from-entity