实体框架5.0实体中缺少.load方法和.local属性 [英] entity framework 5.0 .load method and .local property are missing from entity

查看:137
本文介绍了实体框架5.0实体中缺少.load方法和.local属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架5并拥有两个Visual Studio 2010解决方案。一个是一个小的测试解决方案,一个项目,一个是一个更大的解决方案与多个项目,我正在做实际的业务应用程序。



较小的解决方案中的实体同时拥有 .Load()方法和 .Local 属性。



较大解决方案中的实体具有



我在项目中引用了 system.data.entity EntityFramework



我已经比较了两个解决方案,无法弄清楚大的缺陷是什么。

解决方案

从Pawel的评论中提出,我发现 small solution 基于 DbContext ,它给了我 .Load()方法和 .Local 属性。



要将更大的解决方案切换到 DbContext ,I请从此网页执行以下步骤 http://msdn.microsoft.com/en-US/data / jj206878


接下来,我们需要交换我们的模型来生成使用DbContext API的代码在实体框架的更高版本中。


  1. 在EF Designer中右键单击模型的空白点,然后选择添加代码生成项目...


  2. 从左侧菜单中选择在线模板,并搜索DbContext


  3. 选择用于C#的EF 5.x DbContext生成器,输入YourChoiceOfName作为名称,然后单击添加



我现在拥有 .Local 属性,我怀疑 .Load()方法可用尽管我还没有使用它。


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.

解决方案

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.

  1. Right-click on an empty spot of your model in the EF Designer and select Add Code Generation Item…

  2. Select Online Templates from the left menu and search for DbContext

  3. 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.

这篇关于实体框架5.0实体中缺少.load方法和.local属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆