为什么我有两个表 - AspNetUsers 和 ApplicationUser

Why do I have two tables - AspNetUsers and ApplicationUser

我是 ASP.NET Core MVC 和 EF 的新手。我创建了一个 CatchmebgUser,它继承了 IdentityUser。我在 CatchmebgUser 中为照片添加了自定义字段并应用了迁移。

现在我有两个 table:AspNetUsersCatchmebgUser

使用用户对象时,我从 AspNetUsers table 获取数据,直到我将此行添加到 CatchmebgContext:

builder.Entity<CatchmebgUser>().ToTable("CatchmebgUser");

有没有办法摆脱 AspNetUsers table 或者我应该为用户提供两个单独的 table?

如果您从 IdentityUser 继承自定义 User 类型,则必须改用 IdentityDbContext 的派生版本,它允许您为用户、角色和整个身份框架中使用的主键:

public class MyDbContext : IdentityDbContext<CatchmebgUser, IdentityRole, string>
{
   ...
}

这样您就不必为您的类型添加 builder.Entity<CatchmebgUser>().ToTable("CatchmebgUser") 配置,因为上下文会自动将 DbSet<CatchmebgUser> 用于 Users 属性。