Search code examples
c#.net.net-coreentity-framework-coreasp.net-identity

Change Identity Role Claims Pk type as Guid


I have created a datacontext with all the identity tables with Guid as primary key, but still the IdentityUserClaim and IdentityRoleClaim tables after migration are still has int as primary key. is there any way to change this to Guid as primary key

public class DataContext: IdentityDbContext<IdentityUser<Guid>, IdentityRole<Guid>, Guid, IdentityUserClaim<Guid>, IdentityUserRole<Guid>, IdentityUserLogin<Guid>, IdentityRoleClaim<Guid>, IdentityUserToken<Guid>>
{
    public DataContext(DbContextOptions<DataContext> options): base(options)
    {
            
    }
}

enter image description here


Solution

  • Customize Identity Model says:

    The TKey for IdentityUserClaim is the type specified for the PK of users. In this case, TKey is string because the defaults are being used. It's not the PK type for the UserClaim entity type.

    And IdentityUserClaim class looks like this:

    public class IdentityUserClaim<TKey> where TKey : IEquatable<TKey>
    {
        public virtual int Id { get; set; }
    
        public virtual TKey UserId { get; set; }
    
        public virtual string ClaimValue { get; set; }
    
        public virtual void InitializeFromClaim(Claim claim);
    
        public virtual Claim ToClaim();
    }