[英]Concatenating an IQueryable with an IEnumerable into an IQueryable
[英]Call IQueryable as an IEnumerable, filter done on client side?
我在這里閱讀文章: 帶wcf的N層僵屍 。
我遇到以下語句“ zombieRepository.GetAll()。Where(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));
}
有兩種不同的Where
擴展方法:
System.Linq.Enumerable.Where
:
Func<TSource, Boolean>
參數 Expression<Func<TSource, Boolean>>
參數 如果不確定使用的是哪種方法,請將光標放在其上並單擊F1。 您將被轉到與上面的鏈接之一相對應的頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.