Code: Select all
modelBuilder.Entity()
.HasOptional(p => p.Foo1)
.WithMany(c => c.Foos)
.HasForeignKey(p => new { p.FooId })
.WillCascadeOnDelete(false);
I think the generated code is wrong. As far as I can tell the HasForeignKey line should say:One or more validation errors were detected during model generation:
System.Data.Edm.EdmAssociationType: : Multiplicity conflicts with the referential constraint in Role 'Foo_Foo1_Target' in relationship 'Foo_Foo1'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.
System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Foo_Foo1_Source' in relationship 'Foo_Foo1'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be �1�.
Code: Select all
.HasForeignKey(p => new { p.FooReferenceId })