DbContext没有编译

本文关键字:编译 DbContext | 更新日期: 2023-09-27 18:02:08

我正在一步一步地学习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给出错误…

错误1类型或命名空间名称'DbContext'无法找到(您是否缺少using指令或程序集引用?)

为什么?

DbContext没有编译

您必须将对EntityFramework.dll程序集的引用添加到项目中。最简单的方法是安装相应的NuGet包。如果您已经安装了ASP。当你创建一个新项目时,默认会引用这个NuGet包。如果没有,直接安装。