C# 将IQueryable作为IEnumerable调用,是否在客户端完成筛选?
我在这里读一篇文章: 我遇到了下面的语句“zombieRepository.GetAll().Where(funcomp)”,C# 将IQueryable作为IEnumerable调用,是否在客户端完成筛选?,c#,iqueryable,C#,Iqueryable,我在这里读一篇文章: 我遇到了下面的语句“zombieRepository.GetAll().Where(funcomp)”,GetAll()返回一个IQueryable,但是Where语句在Func参数中传递,该参数实际上将IQueryable接口作为IEnumerable接口调用 此调用的问题是,筛选器是在客户端完成的(读取所有dto.ZombieIncidentout,然后应用筛选器),而不是在sql server端完成的,我的理解正确吗 代码段: var paramStart = Exp
GetAll()
返回一个IQueryable
,但是Where
语句在Func
参数中传递,该参数实际上将IQueryable
接口作为IEnumerable
接口调用
此调用的问题是,筛选器是在客户端完成的(读取所有dto.ZombieIncident
out,然后应用筛选器),而不是在sql server端完成的,我的理解正确吗
代码段:
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));
}
var paramStart=Expression.Parameter(typeof(dtos.ZombieIncident),“x”);
表达式func=Expression.Lambda(
Expression.Call(Expression.Property(paramStart,
typeof(dtos.ZombieIncident).GetProperty(propertyName.GetMethod()),
typeof(String).GetMethod(searchType.ToString(),新类型[]{typeof(String)}),
新表达式[]{Expression.Constant(searchValue,typeof(string))}),
新参数表达式[]{paramStart});
Func funcomp=Func.Compile();
foreach(zombieRepository.GetAll()中的dtos.ZombieIncident zombie.Where(funcomp.ToList())
{
添加(zombieincidenttomapper.FromDTO(zombie));
}
有两种不同的扩展方法:
:
- 接受
Func
参数
- 筛选内存中的集合
:
- 接受
表达式
参数
- 在数据源处筛选集合
如果不确定使用的是哪种方法,请将光标放在该方法上并按F1。您将被发送到与上述链接之一对应的页面。有两种不同的扩展方法:
:
- 接受
Func
参数
- 筛选内存中的集合
:
- 接受
表达式
参数
- 在数据源处筛选集合
如果不确定使用的是哪种方法,请将光标放在该方法上并按F1。您将被发送到与上述链接之一对应的页面。检查您的标题(可编辑:)或IQueryable?不确定僵尸是否有一些特殊的接口…@AlexeiLevenkov,updated你有sql分析器吗?如果是这样,运行它,它将告诉您实际查询在做什么。在快速查看代码时,它看起来像是在数据库端进行查询。请检查标题ICurable:)或IQueryable?不确定僵尸是否有一些特殊的接口…@AlexeiLevenkov,updated你有sql分析器吗?如果是这样,运行它,它将告诉您实际查询在做什么。在快速查看代码时,它看起来像是在数据库端进行查询。