Customize Identityuserclaim

Asked

Viewed 170 times

1

I’m trying to customize the Identity Claims table, through the Identityuserclaim class.

I am using a mapping, through the Entitytypeconfiguration class, but I get the error:

A Configuration for type 'Microsoft.AspNet.Identity.EntityFramework.Identityuserclaim' has already been Added. To Reference the existing Configuration use the Entity() or Complextype() methods.

The Dbcontext Onmodelcreating method 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 class Applicationuserclaimconfiguration maps the class Applicationuserclaim : Identityuserclaim to the same table Userclaim.

Does anyone know how to solve this problem?

Thank you.

  • It seems that you are creating twice the same table tests only with a Configuration only

1 answer

0

Here’s an example mapping can do separate the way you did more this mode also works.

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");
 }
  • So @Eduardo, this method works, but I want to keep the settings separate. That’s why I created the Applicationidentityuserclaimconfiguration class. I removed one of the settings, in this case, Applicationidentityuserclaimconfiguration. But Identity created two tables: Aspnetuserclaims and Userclaim. If I leave the Applicationidentityuserclaimconfiguration and remove the Applicationuserclaimconfiguration, it gives the same previous error. For the record only, the Applicationuserclaimconfiguration class inherits from Entitytypeconfiguration<Applicationuserclaim>. E Applicationuserclaim inherits de Identityuserclaim.

  • yes really mapping with separate api Fluent gets better ,it seems to created same table twice only with different names tries to create only Applicationidentityuserclaimconfiguration or tries to do in mapping differently by creating an entity that inherits from Identityuserclaim and the mapping would be for that entity .

  • In this case, it didn’t work @Eduardo. What you said was exactly what I did. This is the Applicationuserclaimconfiguration: ;public class ApplicationUserClaimConfiguration : EntityTypeConfiguration<ApplicationUserClaim> &#xA;{&#xA; public ApplicationUserClaimConfiguration()&#xA; {&#xA; ToTable("UserClaim");&#xA; }&#xA;} I only created Applicationidentityuserclaimconfiguration : Entitytypeconfiguration<Identityuserclaim>, because of what it says in this article: [http://eduardopires.net.br/2015/02/customizando-names-tabelas-fields-asp-net-identity/]

  • Sorry @Eduardo, I think we’re missing information. In this case, I configure the two classes: Identityuserclaim and Applicationuserclaim, which inherits from Identityuserclaim. , which became respectively Applicationidentityuserclaimconfiguration and Applicationuserclaimconfiguration. That’s clear? rsrs

  • so in your mapping you map Applicationuserclaim no identityUserClaim

  • But if I just map Applicationuserclaim, as below, it creates two tables: Aspnetuserclaims and Userclaim "/ protected override void OnModelCreating(DbModelBuilder modelBuilder)&#xA; {&#xA; base.OnModelCreating(modelBuilder);&#xA;&#xA; //modelBuilder.Configurations.Add(new ApplicationIdentityUserClaimConfiguration());&#xA;&#xA; modelBuilder.Configurations.Add(new ApplicationUserClaimConfiguration());&#xA;&#xA; }

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.