[英]Customize IdentityUserRole in ASP.NET Core
In my asp dotnet core application, I'm changing the default IdentityUser
and the IdentityRole
into my own classes MesUser
and MesRole
在我的asp dotnet核心应用程序中,我将默认的
IdentityUser
和IdentityRole
更改为我自己的类MesUser
和MesRole
public class MesUser : IdentityUser<int>, IUser
{
#region Property
/// <summary>
/// Osobní číslo
/// </summary>
[Column("ID")]
public override int Id { get; set; }
/// <summary>
/// Křestní jméno
/// </summary>
[Column("FIRST_NAME")]
public string FirstName { get; set; }
and set it in dbcontext 并在dbcontext中设置
public DbSet<MesUser> MesUsers { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<MesUser>().ToTable("COR_USERS").HasKey(t => t.Id);
but if I do something similar with any other Identity class I get error message: 但是,如果我对任何其他Identity类执行类似操作,则会收到错误消息:
A key cannot be configured on 'MesRoleUser' because it is a derived type.
无法在“ MesRoleUser”上配置密钥,因为它是派生类型。 The key must be configured on the root type 'IdentityUserRole'.
必须在根类型“ IdentityUserRole”上配置密钥。 If you did not intend for 'IdentityUserRole' to be included in the model, ensure that it is not included in a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation property on a type that is included in the model.
如果您不打算将'IdentityUserRole'包含在模型中,请确保您的上下文中的DbSet属性中未包含它,在ModelBuilder的配置调用中没有引用它,或者在包含的类型上从导航属性引用了它在模型中。
I know that just a link is not the rule but by following this you will learn: 我知道,仅链接不是规则,但是通过遵循此链接,您将学到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.