2013-07-18 41 views
1

我有以下表:的nHibernate QueryOver <T>併發症

客戶=> CustomerAccount =>帳戶

我有一個的nHibernate映射到POCO每個表的以上爲好。

我有一個實現IIdentifier<T>

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

現在我想要做的是通過QueryOver<Account>

加入客戶=> CustomerAccount =>帳戶表對象以下lambda表達式如何我是否添加上面的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); 

感謝,

凱爾

回答

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