4
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::多重性与关系“Attribute_ValueAttribute”中角色“Attribute_ValueAttribute_Target”中的引用约束冲突。因为从属角色中的所有属性都不可为空,所以主体角色的多重性必须为“1”。

啊啊啊啊……

4

1 回答 1

10
public int ? ValueAttributeId { get; set; }

...该属性需要可以为空。

于 2012-02-22T23:33:39.487 回答