我使用的是 RTM 版本的 Windows 8 和 VS 2012 Ultimate.我有一个使用 SqlCe 4.0 和代码优先实体框架模型的 MVC4 项目.
I'm using RTM version of Windows 8 and VS 2012 Ultimate. I have a MVC4 project using SqlCe 4.0 with a code first entity framework model.
模型很简单:
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; } }当我也尝试使用内置脚手架创建新控制器时,我收到以下错误:
When I try to create a new controller with the built in scaffolding too I get the following error:
无法检索 MyThing 的元数据"
"Unable to retrieve metadata for MyThing"
"使用相同的 DbCompiledModel 创建针对不同的上下文不支持的数据库服务器类型.相反,创建一个为正在使用的每种类型的服务器单独的 DbCompiledModel.
"Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.
如何让脚手架发挥作用?
How do I get scaffolding to work?
推荐答案通过反复试验,我发现了导致错误的代码行(它是 DbContext ctor):
By trial and error I found the line of code (it's the DbContext ctor) that is causing the error:
public class MyThingDb : DbContext { // If I comment this constructor out the scaffolding works public MyThingDb() : base("DefaultConnection") { } public DbSet<MyThing> Things{ get; set; } }WTF?
更多推荐
MVC4 脚手架添加控制器给出错误“无法检索元数据...";
发布评论