我有這個型號和配置實體框架代碼第一 - 這兩個領域的聯合成一個集
public class Person
{
public int? FatherId { get; set; }
public virtual Person Father { get; set; }
public int? MotherId { get; set; }
public virtual Person Mother { get; set; }
public virtual List<Person> Childs { get; set; }
}
class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasOptional(e => e.Father).WithMany(e => e.Childs)
.HasForeignKey(e => e.FatherId);
HasOptional(e => e.Mother).WithMany(e => e.Childs)
.HasForeignKey(e => e.MotherId);
}
}
和我得到這個錯誤的類型爲初始。
指定的模式無效。錯誤:(151,6):錯誤0040:類型 Person_Father未在名稱空間ExamModel(Alias = Self)中定義。
有沒有辦法通過兩個屬性(motherId和fatherId)映射Childs
屬性?