错误创建在Visual Studio 2012年时,控制器 [英] Error when creating a Controller in Visual Studio 2012
问题描述
我想学习ASP.NET MVC所以我跟随asp.net网站上的音乐商店教程。
I'm trying to learn ASP.NET MVC so I'm following the Music Store tutorial on the asp.net website.
我在您创建一个使用Album.cs作为模型类MusicStoreEntities.cs作为数据上下文类的StoreManagerController的部分。
I'm at the part where you create the StoreManagerController using Album.cs as the model class and MusicStoreEntities.cs as the data context class.
当我创建了控制器的错误是:无法检索元数据MvcMusicStore.Models.Album。使用相同的DbCompiledModel创建针对不同类型的数据库服务器环境不支持。相反,为每一个类型的服务器单独DbCompiledModel被使用。的
The error when I create the Controller is: Unable to retrieve metadata for 'MvcMusicStore.Models.Album'. 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.
听起来像我用两个不同的数据库,但这里是我的Web.config文件的连接字符串部分:
Sounds like I'm using two different databases, but here is my connection string section from Web.config:
<connectionStrings>
<add name="MusicStoreEntities" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\MvcMusicStore.sdf"/>
</connectionStrings>
奇怪的是,如果我注释掉MusicStoreEntities连接字符串,然后尝试创建它的工作原理StoreManagerController。如果我改变了目标框架中的解决方案设置到.NET Framework 4它也可以在Visual Studio 2010中打开解决方案,然后创建控制器。
The odd thing is if I comment out the MusicStoreEntities connection string and then try to create the StoreManagerController it works. It also works if I change the Target Framework in the solution settings to .NET Framework 4, opening the solution in Visual Studio 2010, and then creating the Controller.
因此,它是与Visual Studio 2012或连接字符串的问题?也许有CE4.0和VS2012一些兼容性问题?
So is it an issue with Visual Studio 2012 or the connection string? Maybe some compatibility issue with CE4.0 and VS2012?
推荐答案
问题在于内使用教程使用的数据库的CE版本。当切换到其他数据库版本,如SQL Server 2012中,它的工作很适合我。试试这个:
Problem lies within using the CE edition of database used in tutorials. When switched to other DB version like SQL server 2012, it worked well for me. Try this:
更改此连接字符串
<add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0"/>
以
<add name="MusicStoreEntities" connectionString="Data Source=DBInstanceName;Initial Catalog=MvcMusicStore;Integrated Security=True" providerName="System.Data.SqlClient" />
这篇关于错误创建在Visual Studio 2012年时,控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!