My Asp.Net MVC system uses Identity in its default form, with some simple customizations. I also have a Physical Persons table (which inherits some information from People, but I think this is not the case).
I would like to associate the ApplicationUser with the PersonPass, so that every ApplicationUser has a PersonPass (PersonPass may or may not have an ApplicationUser).
public class ApplicationUser : IdentityUser { [ForeignKey("PessoaFisica")] public int PessoaFisicaId { get; set; } public virtual PessoaFisica PessoaFisica { get; set; } public async Task GenerateUserIdentityAsync(UserManager manager) { ... } }
In the PersonPass class, I have the following:
[Table("Pessoas")] public partial class PessoaFisica : Pessoa { public int Id { get; set; } public string Nome { get; set; } ... public virtual ApplicationUser Usuario { get; set; } }
The error I get is:
One or more validation errors were detected during model generation:
ApplicationUser_Pessoa_Source:: Multiplicity is not valid in Role 'ApplicationUser_PessoaFisica_Source' in relationship 'ApplicationUser_PessoaPessoa'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
Placing the relationship with fluent API in the model:
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity‹PessoaFisica›() .HasOptional(f => f.Usuario) .WithRequired(s => s.PessoaFisica); }
I also have one error, but it's another one:
Unable to determine the principal end of an association between the types 'WebApplication5.Models.PessoaFisica' and 'WebApplication5.Models.ApplicationUser'. The main end of this association must be explicitly configured using either the fluent relationship API or data annotations.
What am I doing wrong?