有没有一种方法可以在ASP.NET MVC Core中使用实体上下文?

我正在使用ASP.NET Core MVC,但是我正在使用的教程是ASP.NET MVC 3(这是我遇到的最好的特定教程)。当我被要求使用代码优先方法将SQL Server连接到我的项目时,我遇到了障碍。

我已经更改了web.config文件,并创建了一个新类来表示实体框架。尝试执行此操作后,我只是遇到了错误(尤其是using System.Data.Entity;未被识别,DbContextDbSet都不被识别)。

我相信本教程所推荐的内容已过时,我尝试研究一种最新的解决方案,但找不到任何东西。也可能是我添加到配置文件中的<connectionStrings>部分有问题,但是我也找不到任何内容。

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; }
    }
}

作为参考,该教程页面:

Tutorial

hhhhj2006 回答:有没有一种方法可以在ASP.NET MVC Core中使用实体上下文?

您正在遵循的教程标记为2011年4月21日,我建议更新一些。

您可以遵循Razor Pages with Entity Framework Core in ASP.NET Core - Tutorial 1 of 8,该版本已更新为可与3.0一起使用。

  

Visual Studio指令使用SQL Server LocalDB,这是一种仅在Windows上运行的SQL Server Express版本。

     

Visual Studio Code指令使用跨平台数据库引擎SQLite。

另一个选项是Get Started with ASP.NET Core and Entity Framework 6

(一个使用EF Core,另一个使用EF不是Core)。

本文链接:https://www.f2er.com/3133991.html

大家都在问