![](/img/trans.png)
[英]An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
[英]System.InvalidOperationException >> occurred in EntityFramework.dll but was not handled in user code?
我想问一下这个问题。 这是我的代码>
上下文:
public class ArchifeContext: DbContext
{
public DbSet<Department> Departments { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Book> Books { get; set; }
}
控制器:
public ArchifeContext db = new ArchifeContext();
public ActionResult Index()
{
return View(db.Books.ToList());
}
这可能是因为您的数据库与您的上下文不匹配,请尝试备份和删除旧数据库,然后重试。 如果您不想这样做,请尝试通过使用Enable-Migrations
和Update-Database
将更改迁移到Update-Database
试试这个对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.