Reputation: 424
Is there a way to keep efficient counting on Entity Framework? Please, any help would be appreciated.
I am trying to count rows on an EF query, but the count goes in timeout, nevertheless the query itself it is ok.
Tried with .AsNoTracking()
also.
Example:
ObjGetIndexedViewResult.TotRecord = listDocuments.AsNoTracking()
.Select(x => new { x.id })
.Count();
Upvotes: 3
Views: 5130
Reputation: 57
ObjGetIndexedViewResult.TotRecord.Equals(listDocuments.Distinct().AsNoTracking().Select(x => new { x.id }).Count());
Upvotes: 1
Reputation: 40
ObjGetIndexedViewResult.TotRecord = listDocuments.AsNoTracking().Select(x => new { x.id }).Count();
use
Distinct().
Upvotes: -1
Reputation: 424
sorry for bothering ya, just found the solution!
with .Distinct().
ObjGetIndexedViewResult.TotRecord = listDocuments.Distinct().AsNoTracking().Select(x => new { x.id }).Count();
Upvotes: 1