nHibernate QueryOver<T> Complication

本文关键字:Complication gt lt QueryOver nHibernate | 更新日期: 2023-09-27 18:23:59

我有以下表格:

客户=>客户账户=>账户

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

我在一个实现IIdentifier<T> 的对象中有以下lambda表达式

public Expression<Func<ICustomer, bool>> Filter
{
    get { return customer => customer.CustomerNumber == _customerNumber; }
}

现在我要做的是通过QueryOver<Account> 加入Customer=>CustomerAccount=>Account表

如何添加以上类型为Customer的Filter lamdba以按客户编号进行筛选?

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);

谢谢,

Kyle

nHibernate QueryOver<T> Complication

您可以尝试:

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));