Asp.net-Mvc
MVC4 腳手架添加控制器給出錯誤“無法檢索元數據…”
我正在使用 RTM 版本的 Windows 8 和 VS 2012 Ultimate。我有一個使用 SqlCe 4.0 和程式碼優先實體框架模型的 MVC4 項目。
模型很簡單:
public class MyThing { public int MyThingId { get; set; } public int UserId { get; set; } public string Title { get; set; } public string Address { get; set; } public string Description { get; set; } public DateTime Date { get; set; } }當我嘗試使用內置腳手架創建新控制器時,我收到以下錯誤:
“無法檢索 MyThing 的元數據”
“不支持使用相同的 DbCompiledModel 針對不同類型的數據庫伺服器創建上下文。相反,為正在使用的每種類型的伺服器創建單獨的 DbCompiledModel。
如何讓腳手架工作?
通過反複試驗,我找到了導致錯誤的程式碼行(它是 DbContext ctor):
public class MyThingDb : DbContext { // If I comment this constructor out the scaffolding works public MyThingDb() : base("DefaultConnection") { } public DbSet<MyThing> Things{ get; set; } }怎麼回事?