簡體   English   中英

使用Fluent Api定義可選的自引用一對多關系

[英]Define optional self-referencing one-many relationship 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 ::多重性與關系'Attribute_ValueAttribute'中Role'Name_ValueAttribute_Target'中的引用約束沖突。 由於“從屬角色”中的所有屬性都是不可為空的,因此“主體角色”的多重性必須為“1”。

Aaaaahhhh .....

public int ? ValueAttributeId { get; set; }

......該屬性必須是無效的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM