Customize IdentityUserRole in ASP.NET Core

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

Question

In my asp dotnet core application, I'm changing the default IdentityUser and the IdentityRole into my own classes MesUser and 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

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:

A key cannot be configured on 'MesRoleUser' because it is a derived type. The key must be configured on the root type '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.

1
0
1/23/2019 5:47:41 AM

Popular Answer

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.
0
2/7/2018 4:01:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow