私は、EF 流暢な API で非常に一般的なケースのように思われるものをマップしようとしていますが、壁にぶつかっています。私は次のクラスを持っています:
public class Company
{
public int Id { get; set; }
public virtual List<Division> Divisions { get; set; }
public virtual List<Employee> Employees { get; set; }
}
public class Division
{
public int Id { get; set; }
public virtual List<Employee> Employees { get; set; }
public virtual Company Company { get; set; }
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Division Division {get; set;}
}
次の表を使用します。
会社
ID - 整数
区分:
Id - int CompanyId int (FK)
従業員
ID - int
名前 - varchar(50)
DivisionId - int (FK)
Employee テーブルに CompanyID FK がある場合、このマッピングは非常に単純になります。
HasMany(c=>c.Employees).WithRequired().HasForeignKey(e=>e.CompanyId);
ただし、Employee テーブルから Company テーブルへの直接の FK がないため、遅延読み込みのために Company オブジェクトの Employees プロパティをマップできないようです。
私は何が欠けていますか?