I have a performance issue with an EF request.
We basically have this:
public class Article
{
public int ID { get; set; }
public virtual List<Visit> Visits { get; set; }
}
public class Visit
{
public int? ArticleID { get; set; }
public DateTime Date { get; set; }
}
Now I would like to do:
Article a = ...;
vm.Count = a.Visits.Count;
The problem is that from what I can collect, it first causes a selection of the entire list, and then its quantity. When this is done in a loop, this creates a performance problem.
I assumed that this is because the object is "too specific", so I tried to move the call Visits.Countas far as possible to the repository (so we kind of work directly with DbContext). It did not help.
Any suggestions?
source
share