小编Cor*_*dez的帖子

具有一对多关系的自定义身份用户类在数据库中创建额外的列

ASP.NET Core IdentityEntity Framework Coreon一起使用.NET 5,使用带有 postgresql 数据库的代码优先方法。

我正在尝试像这样扩展身份类

public class User : IdentityUser<int>
{
    public ICollection<UserLogin> Logins { get; set; }
}

public class UserLogin : IdentityUserLogin<int>
{
    public User User { get; set; }
}

public sealed class AppDbContext : IdentityDbContext<User, Role, int, UserClaim,UserRole, UserLogin, RoleClaim, UserToken>
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行迁移时,它生成的表看起来像这样 -

在此处输入图片说明

请注意,UserId1已经创建了一个额外的列。

我希望它能够识别UserLogin.User导航Id应该与IdentityUserLogin.UserId属性相对应(根据 MS 在此处制定的约定:https : …

c# entity-framework-core asp.net-core-identity entity-framework-core-migrations .net-5

4
推荐指数
1
解决办法
77
查看次数