加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – MVC4脚手架添加控制器给出错误“无法检索元数据

发布时间:2020-12-15 18:39:59 所属栏目:asp.Net 来源:网络整理
导读:我正在使用RTM版本的Windows 8和VS 2012 Ultimate。我有一个MVC4项目使用SqlCe 4.0与代码第一实体框架模型。 型号很简单: public class MyThing { public int MyThingId { get; set; } public int UserId { get; set; } public string Title { get; set; }
我正在使用RTM版本的Windows 8和VS 2012 Ultimate。我有一个MVC4项目使用SqlCe 4.0与代码第一实体框架模型。

型号很简单:

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; }
  }

当我尝试用内置的脚手架创建一个新的控制器,我得到以下错误:

“Unable to retrieve metadata for MyThing”

“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.

如何让脚手架工作?

解决方法

通过反复尝试,我发现导致错误的代码行(它是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; }
}

WTF?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读