1
我的遺留表「ALLDATA」有這些列:Id, Title, LookupColumn1Id
我的實體:地圖企業自我連接表憑身份證
public class BaseEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Employee: BaseEntity
{
public virtual int DepartmentId { get; set; }
public virtual string DepartmentName { get; set; }
}
public class Department: BaseEntity
{
public virtual int HeadManagerId { get; set; }
}
我要生成選擇這樣的:
SELECT EmployeeTable.Title, DepartmentTable.Id, DepartmentTable.Title
FROM AllData EmployeeTable left outer join AllData DepartmentTable on EmployeeTable.LookupColumn1Id=DepartmentTable.Id
WHERE EmployeeTable.tp_ListId = @p0 and (DepartmentTable.Title = @p1)
謝謝,但它不是答案。我不會在代碼中顯式實現該層上的實體之間的關係,我只想在映射中指定該特定關係。 – dbardakov
關鍵是,你正在嘗試使用NHibernate,這是ORM。換句話說,您將表訪問移動到實體/對象訪問。這意味着,我們必須將表映射到實體,根據它們的DB和Object結構創建關係。然後我們可以通過對象模型的抽象來查詢數據庫 –