1
My Asp.Net MVC system uses Identity in its default form, with a few simple customizations. I also have a table of Individuals (which inherits some information from People, but I don’t think this is the case).
I would like to associate the Applicationuser with Personal Physique, so that every Applicationuser has a Personal Physique (Personal Physique 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 Personal Physics 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 mistake I get is:
One or more validation errors Were Detected During model Generation:
Applicationuser_people_source: Multiplicity is not Valid in Role 'Applicationuser_people_source' in Relationship 'Applicationuser_pessoafisica'. 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 have a mistake too, but it’s another:
Unable to determine the main 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 Relationship Fluent API or data Annotations.
What I’m doing wrong?
Your problem there is that several individuals may refer to the same Applicationuser.
– Fabri Damazio