Entity Framework Designer Errors

北城以北 提交于 2019-12-11 03:35:43

问题


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

回答1:


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.




回答2:


Use NuGet to EF6 instaler but must also install tools for VS2012 or VS2013 EF6



来源:https://stackoverflow.com/questions/15051138/entity-framework-designer-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!