2009-08-27 54 views
0

我有以下情况:LINQ的NHibernate的 - 分隔查询

​​

 var totalRecords = (from entry in invalidAccEntryRepository 
          select entry); 

     if (CustomerAccountInfoFilterActive) 
     { 
      totalRecords.Where(entry => 
           entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName && 
           entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId); 
     } 

     totalRecordsCount = totalRecords.Count(); 

第一查询工作完全,但第二个查询仅执行的唯一

var totalRecords = (from entry in invalidAccEntryRepository 
          select entry); 

并忽略有条件添加的表达式。

任何人都知道问题可能是什么?你需要更多信息吗?

Thx提前!

回答

1

你实际上并没有应用在哪里。在您的if中,请使用此代替:

totalRecords = totalRecords.Where(entry => 
           entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName && 
           entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId); 
+0

非常感谢! – Chris 2009-08-27 13:28:14

+0

克里斯没问题。 :) – 2009-08-27 13:38:20