MVC4 脚手架添加控制器给出错误“无法检索元数据...";

编程入门 行业动态 更新时间:2024-10-24 02:02:27
本文介绍了MVC4 脚手架添加控制器给出错误“无法检索元数据...";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是 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 脚手架添加控制器给出错误“无法检索元数据...";

本文发布于:2023-11-17 00:06:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608076.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚手架   控制器   错误   数据   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!