Modify table AspNetUserClaims Asp.net Identity

1

Good morning,

I have a logic problem with identity.

I need to create an access screen and would like to use the table claim already made available by it. The big problem is that the table creates a foreign key for the AspNetUsers table, I would like this field to be a foreign key of a table that I will create.

How can I change this relationship between tables?

    
asked by anonymous 01.08.2016 / 15:52

1 answer

2

If you are using ASP.NET Identity, the correct is your Usuario inherit from IdentityUser :

public class Usuario : IdentityUser { ... }

The table naming configuration can be changed through the OnModelCreating event using Fluent API :

public class ApplicationDbContext : IdentityDbContext<Usuario>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }

    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>()
            .ToTable("Usuarios", "dbo").Property(p => p.Id).HasColumnName("UsuarioId");
        modelBuilder.Entity<Usuario>()
            .ToTable("Usuarios", "dbo").Property(p => p.Id).HasColumnName("UsuarioId");
    }
}

Similarly, this can be done for IdentityUserClaim :

public class UsuarioIdentificacao : IdentityUserClaim { ... }

And the setting:

        modelBuilder.Entity<IdentityUserClaim>()
            .ToTable("UsuarioIdentificacoes", "dbo").Property(p => p.Id).HasColumnName("UsuarioIdentificacaoId");
        modelBuilder.Entity<UsuarioIdentificacao>()
            .ToTable("UsuarioIdentificacoes", "dbo").Property(p => p.Id).HasColumnName("UsuarioIdentificacaoId");
    
02.08.2016 / 16:38