Define Optional Relationships for Self-Binding to One-Big Number with Fluent Api

public class Attribute { [Key] public int AttributeId { get; set; } [Required, StringLength(100)] public string Name { get; set; } public int ValueAttributeId { get; set; } public Attribute ValueAttribute { get; set; } public IList<Attribute> ValueAttributes { get; set; } } modelBuilder.Entity<Attribute>() .HasOptional(a => a.ValueAttribute) .WithMany(a => a.ValueAttributes) .HasForeignKey(a => a.ValueAttributeId); 

\ tSystem.Data.Entity.Edm.EdmAssociationType :: Multiplicity conflicts with a relational constraint in the Attribute_ValueAttribute_Target role with respect to Attribute_ValueAttribute. Since all properties of the dependent role are not NULL, the multiplicity of the leading role must be "1".

Aaaaahhhh .....

+4
source share
1 answer
 public int ? ValueAttributeId { get; set; } 

... the property must be null.

+10
source

Source: https://habr.com/ru/post/1397795/


All Articles