【问题标题】:Infrastucture does not exist in System.Data.EntitySystem.Data.Entity 中不存在基础结构
【发布时间】:2014-05-30 01:21:00
【问题描述】:

我正在尝试使用实体框架创建 MVC 项目。 我在解决方案中有 3 个项目

  • SerialTracker.Common
  • SerialTracker.Model
  • SerialTracker.Web

Common 和 Model 像库一样编译,所以 Web 正在使用它们。 模型也使用 Common。

我的问题在这里:

模型从 *.edmx 生成 ==> *.Context.tt ==> 自动生成 *.Context.cs:

namespace SerialTracker.Model
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class SerialTrackerEntities : DbContext
    {
        public SerialTrackerEntities()
            : base("name=SerialTrackerEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<Role> Role { get; set; }
        public DbSet<User> User { get; set; }
    }
}

我有错误,System.Data.Entity 中不存在 Infrastucture。我尝试添加一些参考,但我认为问题出在另一个地方。

//编辑: 我为这个项目重新安装了 NuGet 包,但现在我有错误并且不存在

对不起,我的英语不好。

【问题讨论】:

  • 好的,我为这个项目重新安装了 Nuget 包,现在我只有错误, 不存在
  • 不确定您所说的“基础设施”是什么意思...
  • @Maarten 我的意思是 System.Data.Entity.Infrastructure
  • 构建错误是什么异常?
  • Error 3 The type or namespace name 'User' could not be found (are you missing a using directive or an assembly reference?) D:\SerialTracker\SerialTracker.Model\SerialTracker.Context.cs 29 22 SerialTracker.Model Error 2 The type or namespace name 'Role' could not be found (are you missing a using directive or an assembly reference?) D:\SerialTracker\SerialTracker.Model\SerialTracker.Context.cs 28 22 SerialTracker.Model 这些是我的例外

标签: c# asp.net-mvc entity-framework


【解决方案1】:

S̶o̶̶I̶m̶a̶n̶u̶a̶l̶y̶̶a̶d̶d̶e̶d̶̶f̶i̶l̶e̶̶S̶e̶r̶i̶a̶l̶T̶r̶a̶c̶k̶e̶r̶.̶t̶t̶̶t̶o̶̶S̶e̶r̶i̶a̶l̶T̶r̶a̶c̶k̶e̶r̶r̶e̶d̶mx T̶h̶i̶s̶̶f̶i̶l̶e̶̶I̶̶c̶o̶p̶i̶e̶d̶̶f̶r̶o̶m̶̶a̶n̶o̶t̶h̶e̶r̶̶p̶r̶o̶j̶e̶c̶t̶.̶
N̶o̶w̶̶i̶s̶̶p̶r̶o̶j̶e̶c̶t̶̶g̶e̶n̶e̶r̶a̶t̶e̶̶e̶n̶t̶i̶t̶i̶e̶s̶̶R̶i̶g̶h̶t̶.̶

编辑(2014 年 4 月 29 日)
更新答案:
您可以删除文件 *.tt 并使用
重新创建它 添加 -> 新项目 -> EF 5.x DbContextGenerator(或 EF 6.x ...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 2010-09-10
    • 2014-04-30
    • 1970-01-01
    相关资源
    最近更新 更多