简体   繁体   English

在ASP.NET Core中自定义IdentityUserRole

[英]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核心应用程序中,我将默认的IdentityUserIdentityRole更改为我自己的类MesUserMesRole

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: 我知道,仅链接不是规则,但是通过遵循此链接,您将学到:

  • how to change user key type, 如何更改用户密钥类型,
    • in particular you do not need to override members 特别是您不需要覆盖成员
  • that changing the key type for user in identity involves changes in many classes. 更改用户身份密钥的类型涉及许多类的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从IdentityUserRole转换为IdentityRole(ASP.NET Core) - How to convert from IdentityUserRole to IdentityRole (ASP.NET Core) ASP.NET 核心 Web API - 实体类型'IdentityUserRole<long> ' 需要定义一个主键</long> - ASP.NET Core Web API - The entity type 'IdentityUserRole<long>' requires a primary key to be defined 在ASP.NET中的IdentityUserRole 2.0中获取角色名称 - Get Role name in IdentityUserRole 2.0 in ASP.NET ASP.NET CORE 2 - 实体类型'IdentityUserRole<int> ' 是用一个键属性定义的,但是有 2 个值被传递给了 'DbSet.Find' 方法</int> - ASP.NET CORE 2 - Entity type 'IdentityUserRole<int>' is defined with a single key property, but 2 values were passed to the 'DbSet.Find' method 如何从IdentityUserLogin和IdentityUserRole继承asp.net MVC - How to Inherit from IdentityUserLogin And IdentityUserRole asp.net mvc 最佳实践:自定义asp.net core身份授权 - best practice: customize asp.net core identity authorization 如何在 ASP.NET Core 中为 React SPA 自定义身份控制器? - How to customize Identity controller for React SPA in ASP.NET Core? ASP.Net Core 2.1 中的身份&lt; - 自定义 AccountController - Identity in ASP.Net Core 2.1< - Customize AccountController 为 ASP.NET Core 中的选项自定义 JSON 属性名称 - Customize JSON property name for options in ASP.NET Core ASP.NET Core - 如何自定义 IdentityDbContext 中的一些字段 - ASP.NET Core - How to customize some fields in IdentityDbContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM