![](/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.