1
我在这里阅读文章:N-tier Zombie with wcf。调用IQueryable作为IEnumerable,在客户端完成过滤器?
我碰到下面的语句来“zombieRepository.GetAll()。如果(funcComp)”,GetAll()
返回IQueryable
,但where
语句在Func<>
参数传递,这实际上调用IQueryable
接口为IEnumerable
接口。
这个调用的问题是,过滤器在客户端完成(读取全部dtos.ZombieIncident
出来,然后应用过滤器),而不是在SQL服务器端,我的理解是正确的?
代码片段:
var paramStart = Expression.Parameter(typeof(dtos.ZombieIncident), "x");
Expression<Func<dtos.ZombieIncident, bool>> func = Expression.Lambda<Func<dtos.ZombieIncident, bool>>(
Expression.Call(Expression.Property(paramStart,
typeof(dtos.ZombieIncident).GetProperty(propertyName).GetGetMethod()),
typeof(String).GetMethod(searchType.ToString(), new Type[] { typeof(String) }),
new Expression[] { Expression.Constant(searchValue, typeof(string)) }),
new ParameterExpression[] { paramStart });
Func<dtos.ZombieIncident, bool> funcComp = func.Compile();
foreach (dtos.ZombieIncident zombie in zombieRepository.GetAll().Where(funcComp).ToList())
{
zombies.Add(ZombieIncidentDTOMapper.FromDTO(zombie));
}
检查您的标题ICurable :)或IQueryable?不知道僵尸是否有一些特殊的接口.... –
@AlexeiLevenkov,更新 – Benny
你有sql profiler吗?如果是这样,运行它,它会告诉你实际的查询在做什么。在快速查看代码时,它看起来像是在数据库端查询。 – anAgent