但是,使用Entity Framework 5.0.0一切都很完美〜我可以成功构建一个视图.
使用Entity Framework 6.1.3
“There was an error running the selected code generator. ‘Unable to
@H_404_14@
retrieve Metadata for ‘xxx’. Could not find the CLR type for ‘xxx’.我的环境是VS2013 Ultimate(Update4),目标框架4.5.1,C#,MVC5,EF6.1.3 Database First ObjectContext,sql Server 2008.
我的DAL和MVC应用程序在不同的项目中.
我已经通过Nuget和Package Manager控制台命令行提示卸载并重新安装并且所有其他引用都是正确的,检查了两者都使用相同版本的EF6.1.3.
我的Model类
using System; using System.Collections.Generic; using System.Linq; using System.Web; using SysviewData; namespace SysviewWebEF613.Models { public class DisplaySysoutModel { SysviewEntities context = new SysviewEntities(); public IEnumerable<vw_soServerInfo> GetSysouts() { return context.vw_soServerInfo.ToList(); } } }我的控制器
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using SysviewWebEF613.Models; namespace SysviewWebEF613.Controllers { public class DisplaySysoutsController : Controller { // GET: DisplaySysouts DisplaySysoutModel model = new DisplaySysoutModel(); public ActionResult Index() { return View(model.GetSysouts()); } } }关于EF6.1.3
1)我使用的是EF数据库优先建模.由于历史原因,我使用的是ObjectContext.
2)我尝试过使用代码生成策略〜“Legacy ObjectContext”和“T4”〜(清理/重建等)都不起作用〜我得到相同的错误信息.
“There was an error running the selected code generator. ‘Unable to
@H_404_14@
retrieve Metadata for ‘xxx’. Could not find the CLR type for ‘xxx’.但是,如果我使用EF5.0.0~我能够成功构建我的View.
背景信息&为什么我不想使用EF5.0.0
1)我正在使用MVC5开发一个新的Web前端项目,它将在包含23个其他项目的解决方案中替换现有的Web应用程序〜目前使用EF6.1.3并且已经使用EF6.x.x大约2年了.
那么,您可以理解我不愿意改回使用EF5.0.0吗?
2)因此,由于上述原因〜这就是我尝试使用EF6.1.3而不是EF5.0.0的原因.
Is it as simple as EF6.xxx does not support MVC5 scaffolding when using EF ObjectContext?
@H_404_14@我已经和它斗争了好几天了〜我已经广泛研究过这个问题了,虽然我已经看到了几年前报道的类似脚手架问题(MVC4& EF6xx兼容性)〜我理解(可能是错误的)MVC5和EF6. 1.3现在已经解决了那些问题,我还没有看到有人在构建View时遇到问题〜确实〜如果我使用相同的代码〜但是使用EF5.0.0~一切正常.
我在app.config(DAL)和Web.config(MVC项目)中仔细检查了我的连接字符串〜看起来都很正确.
你有任何想法或者你有过类似的经历,你做了什么来解决这个问题?