添加控制器错误无法检索元数据
我想在VS2012中的MVC 4应用程序中添加控制器作为此图像:
模型:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; namespace MvcDemo.Models { public class MovieDB { public int ID { get; set; } public string Title { get; set; } public string Director { get; set; } public DateTime Date { get; set; } } public class MovieDBContext : DbContext { public DbSet Movies { get; set; } } }
连接字符串:
单击“添加”后,会出现此错误:
unable to retrieve metadata for 'MvcDDemo.Models.MovieDB'.Using the same DbCompiledModel to create contexts against different type of database servers is not supported.instead,create a separate DbCompiledModel for each type of server being used.
有什么建议吗?
在Web.config
,将第二个providerName
设置为与第一个providerName
相同,并在创建控制器后撤消该操作!
来自: 这里
如果有人遇到同样的问题,我的post可能有帮助。
我尝试在同一个项目中试验EF6和EF5,我注意到
这就是我所做的,它解决了这个问题:
- 我从Web.config中删除了
标记 - 使用nuget从我的MVC应用程序中卸载entity framework
- 再次安装entity framework到我的MVC应用程序
删除
将providerName="System.Data.SqlServerCe.4.0
更改为providerName="System.Data.SqlClient
以修复此错误。
在尝试脚手架之前不要忘记清洁和重建! 那是我的错。
用户关注providerName = "System.Data.SqlServerCe.4.0"
我有同样的问题,下面是为我解决问题的变化。 不得不改变localhost。 并添加了初始目录=电影。
之前
之后(修复)
参考:
ASP .Net MVC 4,密钥’attachdbfilename’的值无效
在web.config
,删除AttachDBFilename=|DataDirectory|****.mdf
行。