Customize IdentityUserClaim

1

I'm trying to customize the Identity Claims table, through the IdentityUserClaim class.

I'm using a mapping, through the EntityTypeConfiguration class, but I get the error:

The configuration for type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim' has already been added. To reference the existing configuration use the Entity () or ComplexType () methods.

The OnModelCreating method of DbContext, looks like this:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Configurations.Add(new ApplicationUserClaimConfiguration());
    modelBuilder.Configurations.Add(new ApplicationIdentityUserClaimConfiguration());

    modelBuilder.Configurations.Add(new ApplicationIdentityRoleConfiguration());
    modelBuilder.Configurations.Add(new ApplicationRoleConfiguration());

    modelBuilder.Configurations.Add(new ApplicationUserConfiguration());
}

The ApplicationIdentityUserClaimConfiguration class looks like this:

public class ApplicationIdentityUserClaimConfiguration : EntityTypeConfiguration<IdentityUserClaim>
{
    public ApplicationIdentityUserClaimConfiguration()
    {
        ToTable("UserClaim");
    }
}

The ApplicationUserClaimConfiguration class maps the ApplicationUserClaim: IdentityUserClaim class to the same UserClaim table.

Does anyone know how to solve this problem?

Thank you.

    
asked by anonymous 08.03.2016 / 18:54

1 answer

0

Here is an example mapping can do separate the way you did more that way too.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
 base.OnModelCreating(modelBuilder);
 //sobrescrever a entidade IdentityUser pela entidade Usuario
 modelBuilder.Entity<Usuario>().ToTable("Usuarios")
 .Property(u => u.Id).HasColumnName("IdUsuario");
 modelBuilder.Entity<IdentityRole>().ToTable("Perfis");
 modelBuilder.Entity<IdentityUserRole>().ToTable("UsuariosPerfis");
 modelBuilder.Entity<IdentityUserLogin>().ToTable("UsuariosLogin");
 modelBuilder.Entity<IdentityUserClaim>().ToTable("UsuariosClaims");
 }
    
08.03.2016 / 19:01