2013-02-05 39 views
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)); 
       } 
+0

检查您的标题ICurable :)或IQueryable?不知道僵尸是否有一些特殊的接口.... –

+0

@AlexeiLevenkov,更新 – Benny

+0

你有sql profiler吗?如果是这样,运行它,它会告诉你实际的查询在做什么。在快速查看代码时,它看起来像是在数据库端查询。 – anAgent

回答

1

有两种不同Where扩展方法:

System.Linq.Enumerable.Where

  • 接受一个Func<TSource, Boolean>参数
  • 滤镜集合在内存

System.Linq.Queryable.Where

  • 接受一个Expression<Func<TSource, Boolean>>参数
  • 在数据源

如果你不知道你正在使用的方法的滤镜集合,请将光标放在它并击中F1。您将被发送至与上述其中一个链接对应的页面。