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);
で、オプションの自己参照1対多の関係を定義します:参照制約を持つ多重衝突を役割に「Attribute_ValueAttribute_Target」の関係に「Attribute_ValueAttribute」を。依存ロールのすべてのプロパティはnull不可能なので、プリンシパルロールの多重度は「1」でなければなりません。はtSystem.Data.Entity.Edm.EdmAssociationType 流暢アピ
Aaaaahhhh .....
public int? ValueAttributeId {get;セット; } –
EFCFを使用する利点の一部として、 '[Key]'や '[Required]'のような属性でPOCOを修飾する必要はありません。 – Yuck
はい...私のドメインからのEFの参照を避けることができました。 –