nHibernate QueryOver <t>复杂性</t>

时间:2013-07-18 16:21:53

标签: c# nhibernate lambda queryover

我有以下表格:

客户=&gt; CustomerAccount =&gt;帐户

我也有一个nHibernate映射POCO到上面的每个表。

我在实现IIdentifier<T>

的对象中有以下lambda表达式
public Expression<Func<ICustomer, bool>> Filter
{
    get { return customer => customer.CustomerNumber == _customerNumber; }
}

现在我要做的就是加入Customer =&gt; CustomerAccount =&gt;帐户表格通过QueryOver<Account>

如何添加上述Filter lamdba(类型为Customer),以按客户编号过滤?

ICustomer customer = null;
ICustomerAccount customerAccount = null;
IAccount account = null;

var query = QueryOver(() => account)
    .JoinAlias(() => account.CustomerAccounts, () => customerAccount, JoinType.InnerJoin)
    .JoinAlias(() => customerAccount.Customer, () => customer, JoinType.InnerJoin)
    .Where(() => customerAccount.EndDate == null)
    .And(() => account.IsPreferredAccount == true)
    .And(() => ?? Want to add the above Filter() lambda some how here);

谢谢,

凯尔

1 个答案:

答案 0 :(得分:2)

你可以尝试:

var query = QueryOver(() => account)
    .JoinAlias(() => account.CustomerAccounts, () => customerAccount, JoinType.InnerJoin)
    .JoinAlias(() => customerAccount.Customer, () => customer, JoinType.InnerJoin)
    .Where(() => customerAccount.EndDate == null)
    .And(() => account.IsPreferredAccount == true)
    .And(Restrictions.Where<ICustomer>(Filter));