使用 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();