Error: The entity types 'CustomRole' and 'AspNetRoles' can not share table 'AspNetRoles'

0

I've created the entire Identity structure to work with INT instead of GUID. Using DataBase First and included in the database, with a create script, the Identity tables modified (just changed AspNetUsers).

but every time I call:

userManager.Users.ToList();

I get the following error:

  

The entity types 'CustomRole' and 'AspNetRoles' can not share table 'AspNetRoles' because they are not in the same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them

I'll put some snippets of the following code ... but I do not understand My CustonRole just inherits IdentityRole and my AspNetRoles is pristine just like it was automatically created in the first user registry of a reference application. I even have this reference application pointing to the same bank and running without this error. As far as I know the 2 (reference application and my official application) are with identical Identity settings.

POCO entity generated for AspNetRoles:

namespace EFBcoDadosSQL
{
   using System;
   using System.Collections.Generic;

   public partial class AspNetRoles
   {
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public AspNetRoles()
    {
        this.AspNetUsers = new HashSet<AspNetUsers>();
    }

    public int Id { get; set; }
    public string Name { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<AspNetUsers> AspNetUsers { get; set; }
}
}

My CustonRole to work with INT:

public class CustomRole : IdentityRole<int, CustomUserRole>
{ 
   public CustomRole() { } 
   public CustomRole(string name) { Name = name; }
}

My RoleManager:

public class ApplicationRoleManager : RoleManager<CustomRole, int>
    {
        public ApplicationRoleManager(IRoleStore<CustomRole, int> roleStore)
            : base(roleStore)
        {
        }

        public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)
        {
            return new ApplicationRoleManager(new RoleStore<CustomRole, int, CustomUserRole>(new GPSdEntitiesIdentity()));
        }
    }

My Identity Context and ApplicationUser:

public class CustonUsers : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<CustonUsers, int> manager)
    {
        // Observe que o authenticationType deve corresponder àquele definido em CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Adicionar declarações de usuário personalizado aqui
        return userIdentity;
    }
public string LOGIN { get; set; }

    [ForeignKey("STATUS_REGISTROS")]
    public int IDSTATUSREGISTRO { get; set; }

    public virtual STATUS_REGISTROS STATUS_REGISTROS { get; set; }
}

public class GPSdEntitiesIdentity : IdentityDbContext<CustonUsers, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
    public GPSdEntitiesIdentity()
        : base("IdentityConnection")
    {
    }

    public static GPSdEntitiesIdentity Create()
    {
        return new GPSdEntitiesIdentity();
    }
    public virtual DbSet<STATUS_REGISTROS> STATUS_REGISTROS { get; set; }
}

If you need more information just ask. I'm already breaking my head with this configuration for days ... And I just suggested adopting Entity and Identity because it would be simpler than pure ADO. But it has been much more complicated

Note: I did following these excellent tutorials: link

a>

    
asked by anonymous 22.11.2017 / 23:25

0 answers