When I create any relationship with my user class:
namespace Modelo.Cadastro
{
public class Usuario : IdentityUser
{
[StringLength(250, ErrorMessage = "O nome de usuário deve conter no mínimo 3 caracteres", MinimumLength = 3)]
[Required(ErrorMessage = "Informe o nome do usuário")]
public string Nome { get; set; }
//public virtual ICollection<Parecer> Pareceres { get; set; }
}
}
I get the following error when EntityFramework attempts to create the database: One or more validation errors were detected during model generation:
Project02.Persistance.Contexts.IdentityUserLogin :: EntityType 'IdentityUserLogin' has no key defined
Project02.Persistance.Contexts.IdentityUserRole: EntityType 'IdentityUserRole' has no key defined.
I have already checked several solutions, including including the following lines in my context:
base.OnModelCreating(modelBuilder);
or even map the keys to the classes as well:
public class IdentityDbContextAplicacao : IdentityDbContext<Usuario>
{
public IdentityDbContextAplicacao() : base("IdentityDb")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id).Property(p => p.Name).IsRequired();
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
modelBuilder.Entity<IdentityUserLogin>().HasKey(u => new { u.UserId, u.LoginProvider, u.ProviderKey });
}
static IdentityDbContextAplicacao()
{
Database.SetInitializer<IdentityDbContextAplicacao> (new IdentityDbInit());
}
public static IdentityDbContextAplicacao Create()
{
return new IdentityDbContextAplicacao();
}
public class IdentityDbInit : DropCreateDatabaseIfModelChanges<IdentityDbContextAplicacao>
{
}
}
and nothing works! Any other output?