I have a cumbersome list of objects. The count is about 25.837. once I want to filter my object with such this linq expression
underManagementPersonList.OrderByDescending(x => x.BarCode).Where(x => x.CardNum.Contains("0480286000") || x.BarCode.Contains("0480286000") || x.PersonName.Contains("0480286000")).Skip(pageIndex).ToList(); Evaluation timed out System.Collections.Generic.List<GTS.Clock.Model.MonthlyReport.UnderManagementPerson>
I get this error
Evaluation timed out
ALthogh there is no such problem with fewer items like below which jusk I get 100 items
underManagementPersonList.Take(100).OrderByDescending(x => x.BarCode).Where(x => x.CardNum.Contains("0480286000") || x.BarCode.Contains("0480286000") || x.PersonName.Contains("0480286000")).Skip(pageIndex).ToList();
Because this is simply a list of objects then the order is important - you can speed things up by placing your .Where()
before your .OrderByDescending()
underManagementPersonList.Where(x => x.CardNum.Contains("0480286000") || x.BarCode.Contains("0480286000") || x.PersonName.Contains("0480286000")).OrderByDescending(x => x.BarCode).Skip(pageIndex).ToList();
This still has the potentially expensive/slow string.Contains calls on as many as 3 times on 25,837 objects but at least you'll only be sorting the subset of objects which match your Where.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.