使用 Entity Framework Core 将数据关联到默认 ASP.NET UAM 用户

Associate data to default ASP.NET UAM user using Entity Framework Core

尝试创建一个简单的 MVC 应用程序,该应用程序具有基本的用户帐户管理和社交帐户注册。

创建了 ASP.NET 具有个人身份验证的 Core 2.2 应用程序,通过 NuGet(sqlserver 和工具)添加了 EF 核心。我以前用其他语言构建了一些基本的 ASP.NET MVC 应用程序和 MVC 应用程序。

我根据 this tutorial 登录了 Facebook。

现在我迷路了。

有一个 "Data" 目录,里面已经有一堆代码,还有普通的 MVC 目录。但是,我没有看到与我在启动应用程序时可以清楚地访问的与帐户管理相关的任何页面或操作相关联的 MVC 文件,包括 /Identity/Account/Login/Identity/Account/Manage/Identity/Account/Manage/SetPassword,等

虽然在几分钟内启动所有这些功能并 运行 很酷,但我已经处于不知道它如何工作或为什么工作的劣势。搜索任何我希望对此有所了解的东西,都会给我技术文档,让我头晕目眩,并提供零启蒙。

我想要一组与每个用户关联的数据集 ("Books")。一个用户到多本书。鉴于用户(帐户?)模型不在 MVC 应用程序的模型目录中,我认为不应将其添加到该目录中。如果是,我不知道如何与用户建立关联。

这是我在名为 ApplicationDbContextModelSnapshot.cs

的文件中看到的内容
namespace Bookshelf.Data.Migrations
    [DbContext(typeof(ApplicationDbContext))]
    partial class ApplicationDbContextModelSnapshot : ModelSnapshot
    {
        protected override void BuildModel(ModelBuilder modelBuilder)
        {
        ...

        modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
            {
                b.Property<string>("Id")
                    .ValueGeneratedOnAdd();

                b.Property<string>("ConcurrencyStamp")
                    .IsConcurrencyToken();

                b.Property<string>("Name")
                    .HasMaxLength(256);

                b.Property<string>("NormalizedName")
                    .HasMaxLength(256);

                b.HasKey("Id");

                b.HasIndex("NormalizedName")
                    .IsUnique()
                    .HasName("RoleNameIndex")
                    .HasFilter("[NormalizedName] IS NOT NULL");

                b.ToTable("AspNetRoles");
            });

... 等等,看起来相当可读,但与我目前看到的任何教程都不匹配。

TL;DR:

Where/how 我是否正确创建了新模型?是 like this in the Models directory(我习惯了)还是过时了?

无论哪种方式,在为 ASP.NET Core 2.2 提供内置用户帐户管理的情况下,如何正确地将数据与用户相关联?

There's a "Data" directory with a bunch of code in it already, and the normal MVC directories. However, I don't see the MVC files that would correlate to any of the pages or actions associated with the account management I can clearly access when I launch the application, including /Identity/Account/Login, /Identity/Account/Manage, /Identity/Account/Manage/SetPassword, etc.

这是因为从 ASP.NET Core 2.1 Identity 在您的项目中被提供为 Razor Class Library with the ASP.NET Core project templates. If you want to see those Identity related codes and customize then you have to Scaffold Identity

这里有更多详细信息:Scaffold Identity in ASP.NET Core projects

此外,如果您需要 ASP.NET MVC 格式的核心身份,那么这是我的 GitHub Repository,其中 Razor 页面身份已在 ASP.NET 核心 2.2 中转换为 MVC .