OK… learned something last week… did some testing, and proved it myself… passing on the win.
Below are two small sets of code… the first is the way I USED to do it… Second is the way I do it now.
Here the “Old way” we are first COUNTING the number of direct items on the job, and then doing something if there were any:
int directMtlsFound = Db.JobMtl.Where(r=> r.JobNum == job.JobNum && r.Direct).Count();
if (directMtlsFound > 0) {do something here}
But here, we we don’t count… we simply look for “any” record… this means that it will stop looking once it finds one. it only returns a true/false value. In my test, it it seemed to function in at least 1/2 the amount of time.
bool directMtlsFound= Db.JobMtl.Any(r=> r.JobNum == job.JobNum && r.Direct);
if (directMtlsFound) {do something here}
Just having fun making some BPMs more efficient. _
(FYI, i simplified this… yes, you are supposed to also query on company value too!
)
_