我很想知道这两个在所有情况下是否在功能上是等效的.
是否有可能通过更改字典的默认比较器,这两者在功能上会有所不同?
而且,Keys.Contains几乎不能保证更慢?
我有:
Dictionary<int, List<int>> dict = new ...
var a = SomeEntity.Where(f => dict[f.key].Contains(f.someValue))
Run Code Online (Sandbox Code Playgroud)
这会产生错误
LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[System.Int32] get_Item(Int32)' method
Run Code Online (Sandbox Code Playgroud)
与列表一起工作:
List<int> l = new ...
var a = SomeEntity.Where(f => l.Contains(f.someValue))
Run Code Online (Sandbox Code Playgroud)
因此linq对EF的这种限制还是我错过了什么?