我在方法语法中有以下 LINQ 表达式
IEnumerable<PageElement> elements_test = ObjectContext.PageElements
.Where(_dateDebutCheck).Where(_dateFinCheck)
.Where(pe => _activeLanguageCheck(pe, language))
.Where(pe => _typeCheck(pe, typeElement))
IList<PageElement> list = elements_test.ToList();
private readonly Func<PageElement, bool> _dateDebutCheck = pe => pe.DateDebut.HasValue && pe.DateDebut.Value <= DateTime.Now;
private readonly Func<PageElement, bool> _dateFinCheck = pe => !pe.DateFin.HasValue || pe.DateFin.Value > DateTime.Now;
private readonly Func<PageElement, byte, bool> _activeLanguageCheck = (pe, l) => pe.PageElementLanguages.Where(y => y.Active).Select(y => y.LanguageId).Contains(l);
private readonly Func<PageElement, byte?, bool> _typeCheck = (pe, t) => pe.TypeId == t;
我发现当对 ToList 的调用需要很长时间时,我想知道是否有什么我做错了导致性能下降。我此时仅运行 ToList 作为测试,但仅返回大约 7000 条记录需要几秒钟。我该如何改进呢?