BPM Performance (or product configurator C# performance)

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!:laughing:)

_

6 Likes

or just do this

if (Db.JobMtl.Any(r=> r.JobNum == job.JobNum && r.Direct)) { do something }
1 Like

Yes it can be shortcutted, but sometimes marking a variable that “explains” what the query is looking for allows you to do it without needing to add comments. The extra like of code can sometimes add to clarity.

1 Like