实体框架设计器错误 [英] Entity Framework Designer Errors

查看:114
本文介绍了实体框架设计器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个项目是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\\参数2:无法从'string'转换为'System.Data.Entity.Infrastructure.DbCompiledModel'C:\\ \\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 45 57 TRSDataModel



错误3'TRSModel.TRSEntities'不包含'ContextOptions'的定义和没有扩展方法'ContextOptions'接受类型'TRSModel.TRSEntities'的第一个参数可以找到(你缺少一个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.DbCompiledModelC:\Users\user\文件\TRS\TRSModel\TRSEntityModel.Designer.cs 54 78 TRSDataModel



错误6'TRSModel.TRSEntities'不包含'ContextOptions'的定义,没有可以找到扩展方法ContextOptions,接受TRSModel.TRSEntities类型的第一个参数(您是否缺少using指令或程序集引用?)C:\Users\us er \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\TRSEntityModel.Designer.cs 63 59 TRSDataModel



错误8参数2:无法从'string'转换为'bool'C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 63 76 TRSDataModel
错误9'TRSModel.TRSEntities'不包含'ContextOptions'的定义,并且没有扩展方法'ContextOptions'可以接受类型TRSModel.TRSEntities的第一个参数(您是否缺少使用指令或程序集引用?)C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 65 18 TRSDa taModel




  //行10-17 
使用系统;
使用System.ComponentModel;
使用System.Data.EntityClient;
使用System.Data.Objects;
使用System.Data.Objects.DataClasses;
使用System.Linq;
使用System.Runtime.Serialization;
使用System.Xml.Serialization;


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

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

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



//通过将公共类TRSEntities添加到Rene建议的地方
错误返回错误1声明类型TRSModel时缺少部分修饰符.TRSEntities';此类型的另一部分声明存在C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 33 18 TRSDataModel
错误2'TRSEntities':成员名称不能是usere作为它们的包围类型C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 40 30 TRSDataModel


解决方案

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



我仍然不能肯定的一件事是如何使这个名称更改到EF中,以便不会继续承担旧名称。


I have created a project is Visual Studio 2012 and have set up Entity framework through "Database First" approach. However after mapping to the database and generating my Designer.cs file which is supposed to be automatically generated by the framework, I end up with heaps of errors which I can't get where they come from. I have attached the error as a txt file for your review and professional comment.

Please take note that I'm new to the .net framework, specially the EF area. So I'd appreciate if you give me concrete answer so that it would help along the rest of my learning curve.

Error 1 The best overloaded method match for 'System.Data.Entity.DbContext.DbContext(string, System.Data.Entity.Infrastructure.DbCompiledModel)' has some invalid arguments C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 45 32 TRSDataModel

Error 2 Argument 2: cannot convert from 'string' to 'System.Data.Entity.Infrastructure.DbCompiledModel' C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 45 57 TRSDataModel

Error 3 'TRSModel.TRSEntities' does not contain a definition for 'ContextOptions' and no extension method 'ContextOptions' accepting a first argument of type 'TRSModel.TRSEntities' could be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 47 18 TRSDataModel

Error 4 The best overloaded method match for 'System.Data.Entity.DbContext.DbContext(string, System.Data.Entity.Infrastructure.DbCompiledModel)' has some invalid arguments C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 54 55 TRSDataModel

Error 5 Argument 2: cannot convert from 'string' to 'System.Data.Entity.Infrastructure.DbCompiledModel' C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 54 78 TRSDataModel

Error 6 'TRSModel.TRSEntities' does not contain a definition for 'ContextOptions' and no extension method 'ContextOptions' accepting a first argument of type 'TRSModel.TRSEntities' could be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 56 18 TRSDataModel

Error 7 The best overloaded method match for 'System.Data.Entity.DbContext.DbContext(System.Data.Common.DbConnection, bool)' has some invalid arguments C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 63 59 TRSDataModel

Error 8 Argument 2: cannot convert from 'string' to 'bool' C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 63 76 TRSDataModel Error 9 'TRSModel.TRSEntities' does not contain a definition for 'ContextOptions' and no extension method 'ContextOptions' accepting a first argument of type 'TRSModel.TRSEntities' could be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\TRS\TRSModel\TRSEntityModel.Designer.cs 65 18 TRSDataModel

// 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

解决方案

The problem was as I initially suspected. The extended TRSEntities class was declared in the wrong namespace and therefore could not identify the base ObjectContext class leading to TRSEntities class not being able to access the methods of this base class. This happened due to a change of EF name from "TRSModel" to "TRSEntityModel" which apparently did not register inside the ER engine, hence, auto-generating this context file based on the previous namespace.

One thing that I'm still not sure is how to make this change of name sink into the EF so that it would not continue assuming the old name.

这篇关于实体框架设计器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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