簡體   English   中英

調用IQueryable作為IEnumerable,在客戶端完成過濾?

[英]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>參數
  • 過濾內存中的集合

System.Linq.Queryable.Where

  • 接受Expression<Func<TSource, Boolean>>參數
  • 在數據源處過濾集合

如果不確定使用的是哪種方法,請將光標放在其上並單擊F1。 您將被轉到與上面的鏈接之一相對應的頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM