【问题标题】:nHibernate QueryOver<T> ComplicationnHibernate QueryOver<T> 并发症
【发布时间】:2013-07-18 16:21:52
【问题描述】:

我有以下表格:

客户 => 客户帐户 => 帐户

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

我在一个实现 IIdentifier&lt;T&gt; 的对象中有以下 lambda 表达式

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

现在我要做的是通过QueryOver&lt;Account&gt; 加入 Customer => CustomerAccount => Account 表

如何添加上面的Filterlamdba,即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);

谢谢,

凯尔

【问题讨论】:

    标签: c# nhibernate lambda queryover


    【解决方案1】:

    你可以试试:

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

    【讨论】: