Entity framework 实体框架设计器错误

Entity framework 实体框架设计器错误,entity-framework,entity-framework-4,entity-framework-5,Entity Framework,Entity Framework 4,Entity Framework 5,我创建了一个名为Visual Studio 2012的项目,并通过“数据库优先”的方法建立了实体框架。然而,在映射到数据库并生成Designer.cs文件(该文件应该由框架自动生成)之后,我最终遇到了大量错误,我无法了解这些错误的来源。我已将错误附加为txt文件,供您审阅和发表专业意见 请注意,我是.net框架的新手,特别是EF领域。所以,如果你能给我一个具体的答案,我将不胜感激,这样它将有助于我的学习 错误1“System.Data.Entity.DbContext.DbContext(str

我创建了一个名为Visual Studio 2012的项目,并通过“数据库优先”的方法建立了实体框架。然而,在映射到数据库并生成Designer.cs文件(该文件应该由框架自动生成)之后,我最终遇到了大量错误,我无法了解这些错误的来源。我已将错误附加为txt文件,供您审阅和发表专业意见

请注意,我是.net框架的新手,特别是EF领域。所以,如果你能给我一个具体的答案,我将不胜感激,这样它将有助于我的学习

错误1“System.Data.Entity.DbContext.DbContext(string,System.Data.Entity.Infrastructure.DbCompiledModel)”的最佳重载方法匹配具有一些无效参数C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 45 32 TRSDataModel”

错误2参数2:无法从“字符串”转换为“System.Data.Entity.Infrastructure.DbCompiledModel”C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 45 57 TRSDataModel”

错误3“TRSModel.TRSEntities”不包含“ContextOptions”的定义,并且找不到接受“TRSModel.TRSEntities”类型的第一个参数的扩展方法“ContextOptions”(是否缺少using指令或程序集引用?)C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 47 18 TRSDataModel

错误4“System.Data.Entity.DbContext.DbContext(string,System.Data.Entity.Infrastructure.DbCompiledModel)”的最佳重载方法匹配具有一些无效参数C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 54 55 TRSDataModel

错误5参数2:无法从“字符串”转换为“System.Data.Entity.Infrastructure.DbCompiledModel”C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 54 78 TRSDataModel”

错误6“TRSModel.TRSEntities”不包含“ContextOptions”的定义,并且找不到接受“TRSModel.TRSEntities”类型的第一个参数的扩展方法“ContextOptions”(是否缺少using指令或程序集引用?)C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 56 18 TRSDataModel

错误7“System.Data.Entity.DbContext.DbContext(System.Data.Common.DbConnection,bool)”的最佳重载方法匹配具有一些无效参数C:\Users\user\Documents\TRS\TRSModel\TrsSentityModel.Designer.cs 63 59 TRSDataModel

错误8参数2:无法从“字符串”转换为“bool”C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 63 76 TRSDataModel 错误9“TRSModel.TRSEntities”不包含“ContextOptions”的定义,并且找不到接受“TRSModel.TRSEntities”类型的第一个参数的扩展方法“ContextOptions”(是否缺少using指令或程序集引用?)C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 65 18 TRSDataModel


问题正如我最初怀疑的那样。扩展TrSenties类在错误的命名空间中声明,因此无法识别基ObjectContext类,从而导致TrSenties类无法访问此基类的方法。这是由于EF名称从“TRSModel”更改为“TRSEntityModel”,这显然没有在ER引擎中注册,因此,会根据以前的名称空间自动生成此上下文文件


有一件事我仍然不确定,那就是如何使这个名称的更改进入EF,这样它就不会继续使用旧名称了

使用NuGet-to-EF6 Installer,但也必须安装VS2012或VS2013 EF6

请添加TSREnitityModel.Designer.cs中第45-47 54-56 63-65行左右的代码。请求的代码贴在问题区域。请进行ea查看。将行<代码>公共类TrSenties添加到第一行{请说出应该由框架自动生成的代码。是吗?是的,这是一段自动生成的代码,当您将“代码生成策略”设置从“否”更改为“默认”时生成。这将自动生成您的上下文对象。这表示更改此文件可能会导致不需要的结果。在安装VS2012工具之前,我没有EF 6.x DbContext生成器对象。请从以下位置获取它们:
// Lines 10-17
using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;


// Lines 45-47
public TRSEntities() : base("name=TRSEntities", "TRSEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

// Lines 54-56
public TRSEntities(string connectionString) : base(connectionString, "TRSEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

// Lines 63-65
public TRSEntities(EntityConnection connection) : base(connection, "TRSEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}



// Error return by adding the public class TRSEntities to where Rene suggested 
Error   1   Missing partial modifier on declaration of type 'TRSModel.TRSEntities'; another partial declaration of this type exists C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 33  18  TRSDataModel
Error   2   'TRSEntities': member names cannot be the usere as their enclosing type C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 40  30  TRSDataModel