首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >EF DB在添加代码生成项目时首次生成错误

EF DB在添加代码生成项目时首次生成错误
EN

Stack Overflow用户
提问于 2016-05-01 21:12:27
回答 1查看 398关注 0票数 1

我正在尝试为我的edmx运行代码生成,但是每次我这样做的时候,我都会遇到很多错误。

这是生成的Context.cs文件:

代码语言:javascript
运行
复制
//------------------------------------------------------------------------------
/ <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; }

     }
}

我收到的错误如下:

代码语言:javascript
运行
复制
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

为此,我使用Visual Studio 2015,并将EF添加到我的类库项目中。

有人知道为什么它会生成有错误的代码吗?

EN

回答 1

Stack Overflow用户

发布于 2016-06-09 14:52:44

这是因为您在项目中引用了较旧的实体框架dll。解决方案是- 1。首先从引用管理器中删除旧版EF dll的引用。2.然后使用浏览器功能添加较新的EF dll。

对于EF 6.1.3,您将在文件夹"EntityFramework.6.1.3\lib\net45“中获得dll。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36967060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档