从 Entity Framework 5 升级到 6 [英] Upgrade from Entity Framework 5 to 6

查看:23
本文介绍了从 Entity Framework 5 升级到 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将我们的项目从使用 Entity Framework 5 升级到 Entity Framework 6(虽然 NuGets 更新功能)后,我在生成的 Entities 类上收到以下错误:

After upgrading our project from using Entity Framework 5 to Entity Framework 6 (though NuGets update function) i get the following error on my generated Entities class:

错误 1 ​​命名空间System.Data"中不存在类型或命名空间名称Objects"
(您是否缺少程序集参考?)

Error 1 The type or namespace name 'Objects' does not exist in the namespace 'System.Data'
(are you missing an assembly reference?)

我知道这是因为命名空间已更改,我可以通过更改我的导入来手动修复错误:使用 System.Data.Objects;使用 System.Data.Objects.DataClasses;到:使用 System.Data.Entity.Core.Objects;

I understand that this is because the namespace has changed and i can manually fix the error by changing my imports from: using System.Data.Objects; and using System.Data.Objects.DataClasses; To: using System.Data.Entity.Core.Objects;

但是文件是生成的,所以我需要在每次 Update model from Database 之后重新应用此修复程序.要让 EF 生成没有此错误的模型,是否需要进行额外更改.

However the file is generated so i need to reapply this fix after every Update model from Database. Is there something extra to change to get EF to generate the model without this error.

推荐答案

我认为您的问题是,生成实体和上下文的 T4 模板仍在 EF 版本 5 中.

I think your problem is, that your T4 templates, which generate the entitties and the context are still in EF version 5.

首先你要删除当前的代码生成项,它们在模型后面的代码中,即.Context.tt.tt.接下来用在模型设计器中右键->添加一个新的EF版本6代码生成器->添加代码生成项... ->EF 6.x DbContext 生成器.

First you have to delete the current code generation items, which are in the code behind of the model, namely <Modelname>.Context.tt and <Modelname>.tt.Next add a new EF version 6 code generator with Right click in the model designer-> Add Code Generation Item ... -> EF 6.x DbContext Generator.

这篇关于从 Entity Framework 5 升级到 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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