我需要执行看起来像的代码:
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
并且至少包含一对(Key:26; Value:2,4)。
我认为LINQ无法将此Any()表达式转换为SQL。我如何重写这个查询?
答案 0 :(得分: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)
)