I have the following LINQ expression in method syntax
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;
I find that when the ToList call takes quite a lot of time, and I wonder if there is something that I am doing wrong, which leads to performance degradation. I only run ToList at this stage as a test, but only about 7000 records are returned for a few seconds. How can I improve this?
source
share