【发布时间】:2014-03-12 19:05:25
【问题描述】:
假设我有一个内存集合(Persons),我必须在其上应用一些过滤条件。
var distinctproductKeys = persons.Where(d => d.productsDictionary != null)
.SelectMany(d => d.productsDictionary.Keys)
.Distinct();
对比如果我在应用过滤器之前使用 IQueryable
var distinctproductKeys = persons.AsQueryable()
.Where(d => d.productsDictionary != null)
.SelectMany(d => d.productsDictionary.Keys)
.Distinct();
我已经读过,一旦你在内存中收集了集合,IQueryable 和 IEnumerable 都会提供相同的性能。但是运行我观察到的 IQueryable 版本的两个查询更快。有人能告诉我为什么吗?
【问题讨论】:
-
Persons 是什么类型的?
-
你能告诉我们,你是如何测试它的,你得到了什么结果?
标签: c# performance entity-framework ienumerable iqueryable