我越来越想与CRUD操作和EF添加控制器时出现以下错误:
I'm getting an the following error when trying to add a controller with CRUD actions and EF:
无法检索元数据LetLord.Models.Tenant。使用相同DbCompiledModel创建针对不同类型的数据库的上下文不被支持。相反,创建一个单独的DbCompiledModel为正在使用的服务器的每一种类型。
Unable to retrieve metadata for LetLord.Models.Tenant. Using the same DbCompiledModel to create contexts against different types of databases is not supported. Instead create a separate DbCompiledModel for each type of server being used.
添加控制器对话框中设置:
Add Controller dialog settings:
模板: MVC控制器,具有读/写操作和视图,使用EF
Template: MVC controller with read/write actions and views, using EF.
模型类:租客(LetLord.Models)
Model class: Tenant (LetLord.Models)
数据上下文类: LetLordContext(LetLord.Models)
Data context class: LetLordContext (LetLord.Models)
我见过类似的问题/问题,并尝试提供的解决方案,但我的不能得到它的工作。
I've seen similar questions/problems, and tried the solutions offered but I cannot get it to work.
我的连接字符串:
<connectionStrings> <add name="LetLordContext" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings>在 LetLordContext.cs 我没有默认构造函数。在我的 InitializeSimpleMembershipAttribute.cs 类我称之为
In LetLordContext.cs I don't have a default constructor. In my InitializeSimpleMembershipAttribute.cs class I call
WebSecurity.InitializeDatabaseConnection("LetLordContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);我已经试过:
- 在不同的问题说明更改我的提供程序名称。
- 删除连接字符串和注释出来。
- 删除并重新安装实体框架。
- 确保我的SQL Server CE 4.0安装。
- 又回到了我的Subversion项目的早期版本。
我仍处于亏损状态,因此任何帮助将非常AP preciated。
I'm still at a loss, so any help would be much appreciated.
推荐答案已经找到解决办法,但我还是浑然不觉是什么导致这个错误。
Have found a workaround, but I'm still oblivious to what was causing this error.
在根web.config文件中,我改变
In the root web.config file I changed
<connectionStrings> <add name="LetLordContext" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings>到
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings>这让我补充脚手架和添加一次意见,我改变了字符串回到它最初。据我所知的任何新的字符串就可以了。
This let me add views with scaffolding and once added, I changed the string back to what it was originally. As far as I'm aware any new string will do.
更多推荐
MVC 4添加控制器脚手架给错误
发布评论