使用 JoinAlias 進行連線查詢
可以使用 JoinAlias 方法連線多個表。當需要在 select 語句中指定連線表中的某些屬性時,它很有用:
Customer customerAlias = null;
Organization organizationAlias = null;
IList<Customer> customers = session.QueryOver(() => customerAlias)
.Left.JoinAlias(x => x.Organization, () => organizationAlias)
.Where(customer => customer.Name == "Customer Name")
.And(() => customerAlias.Age > 18)
.AndNot(() => organizationAlias.Name == "Forbidden Organization")
.List();