MVC"新增控制器"是"无法检索元数据... ...配置系统初始化失败" [英] MVC "Add Controller" is "Unable to Retrieve Metadata...Config System Failed to Initialize"

查看:367
本文介绍了MVC"新增控制器"是"无法检索元数据... ...配置系统初始化失败"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从无到有,我做了两个项目一个新的解决方案:一个是MVC 3,另一个是支持EF 4.2项目。整个事情成功生成。从MVC项目,我打开添加控制器的对话,并将它基于我从支持EF项目选择的背景和模型生成code。 添加控制器对话失败消息:

From scratch, I made a new solution with two projects: one was MVC 3 and the other a supporting EF 4.2 project. The whole thing builds successfully. From the MVC project I open the "Add Controller" dialogue and have it generate code based on the context and model I select from the supporting EF project. The "add controller" dialogue fails with the message:

无法检索MyModelClass的元数据。配置系统初始化失败。

Unable to retrieve metadata for 'MyModelClass'. Configuration system failed to initialize.

我注意到,添加控制器对话实际上是试图获取其web.config文件中的数据库连接字符串。首先,这令我傻傻十岁上下,由于支撑EF项目已经与连接字符串一个app.config。但从未介意,我可以计算的最好的是,在web.config中的连接字符串是坏的莫名其妙。这是什么样子:

I've noticed that the "add controller" dialogue is actually attempting to fetch the database connection string from its web.config file. First, this strikes me as goofy-ish, since the supporting EF project already has an app.config with the connection string. But never-minding that, the best I can figure is that the connection string in the web.config is bad somehow. This is what it looks like:

<add name="Monsters2Entities" 

    connectionString="
      metadata=res://*/Monsters.csdl|
               res://*/Monsters.ssdl|
               res://*/Monsters.msl;
      provider=System.Data.SqlClient;
      provider connection string=&quot;
        data source=.;
        initial catalog=Monsters2;
        integrated security=True;
        pooling=False;
        multipleactiveresultsets=True;
        App=EntityFramework
      &quot;" 
      providerName="System.Data.EntityClient" 
/>

连接字符串实际上并不拥有所有的荒谬换行和缩进 - 我只是想,使其更容易阅读。无论如何,该连接串基本相同在支撑EF项目其所建模中使用的连接字符串。我该如何纠正这种状况,使添加控制器dialgoue幸福吗?

The connection string doesn't actually have all the ridiculous line breaks and indentation - I'm just trying to make it easier to read. Anyway, that connection string is basically identical to the connection string used in the supporting EF project upon which it is modelled. How do I correct the situation, to make the "add controller" dialgoue happy?

推荐答案

我已经安装了它增加EF 6:

I had installed EF 6 which added:

<providers>
    <provider invariantName="System.Data.SqlClient" 
        type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

在我的配置文件。我有其他的脚手架问题,于是决定回退到EF 5 EF卸载6和重新安装EF 5我删除了从配置,然后我是能够建立我的新控制器之后。我利用这个发现的

In my config file. I had other scaffolding issues and so decided to fall back to Ef 5. After uninstalling EF 6 and reinstalling EF 5 I deleted the from the config and then I was able to build my new controller. I discovered this by using the

PM> Update-Database –Verbose

这篇关于MVC&quot;新增控制器&QUOT;是&QUOT;无法检索元数据... ...配置系统初始化失败&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆