問題的來龍去脈
Visual Studio 2012在安裝【Web Tools 2012.2】正式版更新之後,ASP.NET MVC 3與ASP.NET MVC 4(C#與VB.NET)專案,如果使用【Database first + Entity Framework】會無法新增MVC Controller與API Controller。
Database first示意圖
- 新增範例資料庫
- 新增Entity Framework實體資料模型(EDMX)
新增MVC / API Controller之英文版錯誤訊息:
'ProjectName.ClassName' is not part of the specified 'ProjectName.???Entities' class, and the 'ProjectName.???Entities' class could not be modifed to add a 'DbSet<ProjectName.ClassName>' property to it.(For example, the 'ProjectName.???Entities' class might be in a compiled assembly.)
新增MVC / API Controller之中文版錯誤訊息:
'ProjectName.ClassName'不是指定之'ProjectName.???Entities'類別的一部分,而且無法修改'ProjectName.???Entities'類別以新增'DbSet<ProjectName.ClassName>'屬性(例如,'ProjectName.???Entities'類別可能位於已編訪的組件中)