身份ASP.NET Core 3.0-找不到IdentityDbContext

Pau*_*ton 7 c# asp.net-core asp.net-core-3.0

我的应用打破了.NET core的3.0版本,并带有的参考错误IdentityDbContext。我正在浏览核心3.0上的Identity的文档,但这意味着IdentityDbContext应该存在。这是我遇到的仅有的几个DbContext错误。

我有一个非常简单的API,没有MVC视图,只有一个返回JSON对象的数据服务器。它基于身份,因此具有用户,角色和声明。它开始利用这一优势。我的主要DbContext进行了扩展,IdentityDbContext<ApplicationUser>但是在升级后将目标平台切换到3.0之后,它说它不存在,并给了我编译错误。有人碰到这个吗?我想念什么吗?迁移和重大更改页面似乎无法解决我的问题。

DbContext看起来像这样:

using System;
using Microsoft.AspNetCore.Identity;
//using Microsoft.AspNetCore.Identity.EntityFrameworkCore; <- this no longer works either
using Microsoft.EntityFrameworkCore; //<- this I had to download as a package
using App.Constants;
using App.Models.Identity;

namespace App.Models
{
    public class AppContext : IdentityDbContext<ApplicationUser> //<- error is right here
    {
        ... my models
    }
}
Run Code Online (Sandbox Code Playgroud)

Tan*_*jel 11

ASP.NET 3.0的核心Entity Framework Core以及Identity相关的包已经从删除Microsoft.AspNetCore.App元数据包。因此,您必须单独添加这些软件包。

将以下PackageReferences 添加到项目的.csproj文件中,如下所示:

<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
Run Code Online (Sandbox Code Playgroud)

现在它将起作用!

有关更多详细信息:从ASP.NET Core共享框架中删除程序集