【发布时间】:2013-11-12 13:59:53
【问题描述】:
我刚刚安装了 MVC4。
根据 nuGet 包管理器,我的 EF 版本是 5.0.0,最后更新于 2012 年 9 月 11 日
当我尝试创建新控制器时(右键单击控制器 -> 添加 -> 控制器),我遇到错误消息并且无法创建新控制器...
Could not load type 'System.ComponentModel.DataAnnotations.Schema.TableAttribute'
from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
我刚刚开始使用 ASP.NET MVC,所以如果有人可以帮助我解决,将不胜感激。
从包管理器控制台,我尝试如下卸载并重新安装实体框架,但这没有任何效果:
PM> Uninstall-Package EntityFramework
Successfully removed 'EntityFramework 5.0.0' from GD.
Successfully uninstalled 'EntityFramework 5.0.0'.
PM> Install-Package EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 5.0.0'.
Successfully added 'EntityFramework 5.0.0' to GD.
Type 'get-help EntityFramework' to see all available Entity Framework commands.
PM>
非常感谢您的所有帮助。
更新:
我正在学习本教程。 http://msdn.microsoft.com/en-us/data/gg685467.aspx
看来MVC4不喜欢这种创建DBContext的方法……
Also there will be a new reference listed in the project references
called EntityFramework. This is the assembly that contains the Code
First runtime.
Add a new class to the Models folder and name it BlogContext. Modify
the class to match the following code:
using System.Data.Entity;
namespace MVC3AppCodeFirst.Models
{
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public DbSet<Comment> Comments { get; set; }
}
}
它构建得很好,所以我错过了什么???
【问题讨论】:
-
您是否尝试清理您的解决方案? (右键解决方案->清理解决方案)
-
出于某种原因,您的 web.config 中有一个 EF 4.1 引用。这是一个新项目,还是要将 EF5 添加到现有的 EF4 项目?
-
这是一个全新的项目。这就是为什么我认为这是一个配置错误。我安装了 EF5,但似乎所有引用都指向 EF4 ???我认为它没有正确安装...
-
@Gravy - 这是 Visual Studio 2010 还是 2012?
-
会不会是您不小心安装了 MVC3 而不是 MVC4?
标签: asp.net-mvc entity-framework