我正在尝试使用 Entity Framework 创建 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 包,但现在我有错误并且不存在
抱歉我的英语不好。
最佳答案
s̶o̶̶̶̶̶
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 ...)
关于c# - System.Data.Entity 中不存在基础结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13969642/