The background task I am running in my asp.net application is taking long time to execute and is getting stuck at a linq query.How to optimize the linq query or can you suggest some alternatives so that this method or this linq can be speeded up.
Linq is something like this:
Litigation i = litigationsNotClosed.SingleOrDefault(x => x.Id_local == d.Id_local && x.LegalEntityID_local == importEntity);
2
Answers
Make sure litigationsNotClosed variable is a IQueryable and not a materialized result. Try to change the code to:
An explanation will be posted if it works.
Does your Linq query use EF DbContext to connect to SQL? How do you provide the context? I think if you create DbContext in a
using
statement inside of your background task, it may solve your problem.