c# - DbContext 没有编译?

标签 c# .net entity-framework compiler-errors

我正在逐步学习 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/

相关文章:

.net - 在源代码中存储敏感信息的最佳实践

c# - .Net Core 2.2 中是否有 SaveFileDialog?

c# - 如果没有匹配项,则获取第一个单个匹配元素或第一个?

javascript - 通过 Web 套接字网络在 C# 服务器上传输 JSON 字符串数据

c# - 如何在 Fluent NHibernate 上设置 SysCache?

c# - 本地化枚举描述属性

entity-framework - Entity Framework 和 System.Data.Sqlite 日期时间问题

c# - 如何强制 EF 使用连接而不是拆分复杂的查询?

c# - Entity Framework 和连接表达式中的一对多配置

c# - 为什么 .net 核心依赖注入(inject)对我不起作用?