Upgrade from Entity Framework 5 to 6(从 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.
首先你要删除当前的代码生成项,它们在模型后面的代码中,即和.接下来用在模型设计器中右键->添加一个新的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Entity Framework 5 升级到 6
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
