sql - Linq Performance with predicates -


i'm refactoring project @ moment, has lot of similar queries on page

db.wf_process.where(x=>x.workflowprocessstate ==  (int)workflowprocessstateenum.subtitlefileversion &&  x.workflowprocesssubstate == (int)subtitlefileprocessenum.subtitleqcreferred).count();  db.wf_process.where(x=>x.workflowprocessstate ==  (int)workflowprocessstateenum.subtitlefileversion && x.workflowprocesssubstate == (int)subtitlefileprocessenum.qcuserfailed).count(); 

this produces following sql runs quick

select  [groupby1].[a1] [c1] ( select      count(1) [a1]     [dbo].[wf_process] [extent1]     (4 = [extent1].[workflowprocessstate]) , (119 = [extent1].[workflowprocesssubstate]) )  [groupby1] 

//repeat above queries 100 different enum values

to clean code bit i've refactored below method

 private int getsubtitleprocesscount(func<wf_process, bool> predicate)         {             return                 db.wf_process.where(x => x.workflowprocessstate == (int)workflowprocessstateenum.subtitlefileversion)                     .where(predicate)                     .count();         } 

called this

model.subtitleqcreferred = getsubtitleprocesscount(x=> x.workflowprocesssubstate == (int)subtitlefileprocessenum.subtitleqcreferred); 

this produces sql

select  [extent1].[processid] [processid],  [extent1].[materialid] [materialid],  [extent1].[videoversionid] [videoversionid],  [extent1].[audioversionid] [audioversionid],  [extent1].[txversionid] [txversionid],  [extent1].[xmlversionid] [xmlversionid],  [extent1].[subtitleversionid] [subtitleversionid],  [extent1].[progress] [progress],  [extent1].[processstatusdescription] [processstatusdescription],  [extent1].[workflowprocessstate] [workflowprocessstate],  [extent1].[workflowprocesssubstate] [workflowprocesssubstate],  [extent1].[processstate] [processstate],  [extent1].[processstatedatelastmodified] [processstatedatelastmodified],  [extent1].[datecreated] [datecreated],  [extent1].[datelastchecked] [datelastchecked],  [extent1].[sleepuntil] [sleepuntil],  [extent1].[longrunningprocessid] [longrunningprocessid] [dbo].[wf_process] [extent1] 4 = [extent1].[workflowprocessstate] 

which retrieves entire record set , performs count in code.

i'm assuming second clause. why this?

is there way of keeping pattern i'm using (with small) modification produces decent sql?

if change accepted type of method expression<func<wf_process, bool>> should convert count logic sql.

i.e.:

getsubtitleprocesscount(expression<func<wf_process, bool>> predicate) 

the documentation on predicatebuilder has more info this.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -