//On model creating :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Person
modelBuilder.Entity<Person>().HasKey(e => e.PersonID)
.ToTable("Persons")
.Property(e => e.PersonID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
//Referancial
modelBuilder.Entity<Referancial>().HasKey(e => e.KeyID)
.ToTable("Referancials")
.Property(e => e.KeyID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
//Translation
modelBuilder.Entity<Translation>().ToTable("Translations")
.HasKey(e => e.KeyID)
.Property(e => e.KeyID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
modelBuilder.Entity<Referancial>()
.HasOptional(e=>e.Translations)
.WithMany()
.HasForeignKey(e => e.KeyID);
base.OnModelCreating(modelBuilder);
}
but it shoz me an error :
One or more validation errors were detected during model generation:
PersonSearch.Models.Referancial_Translations: : Multiplicity conflicts with the referential constraint in Role 'Referancial_Translations_Target' in relationship 'Referancial_Translations'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.
Referancial_Translations_Source: : Multiplicity is not valid in Role 'Referancial_Translations_Source' in relationship 'Referancial_Translations'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be '1'.