2009-08-27 55 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