当我在4.0中构建它时,更新我的EF模型以使用4.1 [英] Updating my EF model to use 4.1 when I built it in 4.0

查看:125
本文介绍了当我在4.0中构建它时,更新我的EF模型以使用4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EF 4.0中构建了我的EF模型,然后安装了包含新DBContext界面的4.1升级。如何更新我的模型,以便使用4.1功能?



谢谢

解决方案

您可以将DbContext与您的EDMX型号一起使用。安装EFv4.1后,您应该可以使用新的T4模板:DbContext生成器。这将使您的EDMX并为您创建从 DbContext 和所有POCO实体派生的上下文。 这里你有演练。



但是如果你想切换到 DbContext 只是因为 DbContext.Entry.State 你不必。 EFV4有一个类似的机制:

  context.ObjectStateManager.ChangeObjectState(entity,EntityState.Modified); 

这里是如何更新EFv4中的实体的完整说明。


I built my EF Model in EF 4.0, and then installed the 4.1 upgrade that includes the new DBContext interface. How do I update my model so that it uses the 4.1 features going forward?

Thank You

解决方案

You can use DbContext with your EDMX model. After installing EFv4.1 you should have new T4 template available: DbContext generator. This will take your EDMX and create context derived from DbContext and all POCO entities for you. Here you have walkthrough.

But if you want to switch to DbContext just because of DbContext.Entry.State you don't have to. EFv4 has a similar mechanism:

context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

Here is the full description how to update an entity in EFv4.

这篇关于当我在4.0中构建它时,更新我的EF模型以使用4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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