我正在逐步学习 mvc 并创建音乐商店,但由于某种原因我无法使以下代码正常工作..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcMusicStore.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
DBcontext、DbSet 和 DbSet 出错...
Error 1 The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
为什么?
最佳答案
您必须将对 EntityFramework.dll
程序集的引用添加到您的项目中。最简单的方法是安装相应的 NuGet package .如果您安装了 ASP.NET MVC 3 Tools Update创建新项目时默认引用此 NuGet 包。如果没有,只需安装它。
关于c# - DbContext 没有编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6691240/