I have a linq query which tries to fetch approximately 500K records from DB. I have a Count() which eventually timing out.
I want to know if my linq query contains 5000 or more records or not. I don't count of all records, just need to check if linq contains 5000 records.
Is there any effective way to check if there 5000 or more records in linq without calling Count()? I am using EF core 3.1.
Linq Query :
var results = (from a in RepoContext.Employee
join b in RepoContext.Program on a.ProgramId equals b.ProgramId
where a.ActiveFlag == true
&& b.ClientId == 2
select new RAManufacturerDto
{
BusinessName = a.BusinessName,
ClientId = a.ClientId.Value,
ClientName = b.ClientName
DCode = b.DCode,
StoreId = b.StoreId,
ProgramId = a.ProgramId
});
bool isRecordsLimitReached = results.Count() > 5000;
I am getting an error when trying to do Count() on result. I just want to get if it contains more than 5000 records.