我刚刚安装了 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; }
}
}
它构建得很好,所以我错过了什么???