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


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01