C# EF DB在添加代码生成项时首先生成错误
我正在尝试为我的edmx运行代码生成,但是每次这样做时,我都会面临许多错误 这是生成的Context.cs文件:C# EF DB在添加代码生成项时首先生成错误,c#,entity-framework,visual-studio-2015,C#,Entity Framework,Visual Studio 2015,我正在尝试为我的edmx运行代码生成,但是每次这样做时,我都会面临许多错误 这是生成的Context.cs文件: //------------------------------------------------------------------------------ / <auto-generated> // This code was generated from a template. // // Manual changes to this file m
//------------------------------------------------------------------------------
/ <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace project.DAL
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class NebulabEntities : DbContext
{
public NebulabEntities()
: base("name=NebulabEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Commodity> Commodities { get; set; }
public virtual DbSet<CommoditiesPrice> CommoditiesPrices { get; set; }
}
}
//------------------------------------------------------------------------------
/
//此代码是从模板生成的。
//
//手动更改此文件可能会导致应用程序出现意外行为。
//如果重新生成代码,将覆盖对此文件的手动更改。
//
//------------------------------------------------------------------------------
名称空间项目.DAL
{
使用制度;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
公共部分类星云实体:DbContext
{
公共星云实体()
:base(“名称=星云实体”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
抛出新代码FirstException();
}
公共虚拟数据库集{get;set;}
公共虚拟数据库集商品价格{get;set;}
}
}
我得到的错误是:
Severity Code Description Project File Line
Error CS0426 The type name 'Data' does not exist in the type 'System' project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 13
Error CS0426 The type name 'Data' does not exist in the type 'System' project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 14
Error CS0246 The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 16
Error CS0115 'NebulabEntities.OnModelCreating(DbModelBuilder)': no suitable method found to override project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 23
Error CS0246 The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?) project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 23
Error CS0246 The type or namespace name 'DbSet<Commodity>' could not be found (are you missing a using directive or an assembly reference?) project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 28
Error CS0246 The type or namespace name 'DbSet<CommoditiesPrice>' could not be found (are you missing a using directive or an assembly reference?) project.DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 29
严重性代码描述项目文件行
错误CS0426类型“System”项目中不存在类型名称“Data”。DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 13
错误CS0426类型“System”项目中不存在类型名称“Data”。DAL C:\Test\project.DAL\RedSpiderDataModel.Context.cs 14
错误CS0246找不到类型或命名空间名称“DbContext”(是否缺少using指令或程序集引用?)
错误CS0115“NebulateEntities.OnModelCreating(DbModelBuilder)”:未找到覆盖project.DAL的合适方法C:\Test\project.DAL\RedSpiderDataModel.Context.cs 23
错误CS0246找不到类型或命名空间名称“DbModelBuilder”(是否缺少using指令或程序集引用?)
错误CS0246找不到类型或命名空间名称“DbSet”(是否缺少using指令或程序集引用?)
错误CS0246找不到类型或命名空间名称“DbSet”(是否缺少using指令或程序集引用?)
为此,我使用Visual Studio 2015,并将EF添加到我的类库项目中
有人知道它为什么生成有错误的代码吗?这是因为您在项目中引用的是较旧的实体框架dll。解决办法是—— 1.首先从引用管理器中删除旧EF dll的引用。 2.然后使用浏览器功能添加较新的EF dll
对于EF 6.1.3,您将在文件夹“EntityFramework.6.1.3\lib\net45”中获得dll这是因为您在项目中引用的是较旧的实体框架dll。解决办法是—— 1.首先从引用管理器中删除旧EF dll的引用。 2.然后使用浏览器功能添加较新的EF dll
对于EF 6.1.3,您将在文件夹“EntityFramework.6.1.3\lib\net45”中获得dll您有解决我面临的相同问题的解决方案吗?您有解决我面临的相同问题的解决方案吗?谢谢,我将试一试。我想我已经确定我删除了EF的所有参考资料,但我可能错过了一个参考资料。谢谢,我会尝试一下。我想我已经确定我删除了EF之前的所有引用,但我可能错过了一个引用。