2012-08-08 86 views
0

使用字典 我需要執行的代碼看起來像: 在LINQ查詢

Dictionary<Int64, List<Int64>> types; 
// initialization of dictionary 
results = (from m in d.Linq() 
      where (filter.Types.Any(x => 
           x.Key == m.DocumentType.Code 
           && x.Value.Contains(m.DocumentPurpose.Code) 
           ) 
       ) 
      select m 
     ).ToList(); 

當我執行這項測試中,我收到System.NullReferenceException。但我確信對象types不是null幷包含至少一對(鍵:26;值:2,4)。

我認爲LINQ無法將此Any()表達式轉換爲SQL。我如何重寫這個查詢?

+1

什麼是'D'變量? – user854301 2012-08-08 05:31:38

+0

它究竟在哪裏指向'NullReferenceException'?我看到了幾個可能的地方,這與LINQ無關。 – 2012-08-08 05:31:50

+0

什麼是'd'?什麼是「過濾器」? 「使用的類型」在哪裏? – 2012-08-08 05:32:28

回答

2

試試這個:

results = (from m in d.Linq() 
      where (m.DocumentType != null && 
        m.DocumentPurpose != null && 
        filter.Types.Any(x => 
           x.Key == m.DocumentType.Code 
           && x.Value.Contains(m.DocumentPurpose.Code) 
           )