entity framework - Linq query containing sum and subquery not working -
i bit new linq , entity framework , have requirement write linq query in data access layer. sql want produce is:
select c.configurationid, configurationdescription, coalesce(d.enrolment,0) enrolment, coalesce(d.accepts,0) accepts, coalesce(d.rejects,0) rejects, coalesce(d.incomplete,0) incomplete vvconfiguration c (nolock) left join ( select configurationid, sum(case when d.dialoguestatusid = 1 , d.processtypeid = 1 , e.createdate = dates.maxcreatedate 1 else 0 end) enrolment, sum(case when ec.verificationdecisionid in (2, 3, 5) , d.processtypeid = 2 , e.createdate = dates.maxcreatedate 1 else 0 end) accepts, sum(case when ec.verificationdecisionid = 6 , d.processtypeid = 2 , e.createdate = dates.maxcreatedate 1 else 0 end) rejects, sum(case when d.dialoguestatusid = 4 , (e.createdate = dates.maxcreatedate or e.createdate null) 1 else 0 end) incomplete dbo.dialogue d (nolock) left join exchange e (nolock) on e.dialogueid = d.dialogueid left join exchangeclaimant ec on e.exchangeid = ec.exchangeid left join (select a.dialogueid,max(ex.createdate) maxcreatedate dialogue (nolock) join exchange ex (nolock) on a.dialogueid = ex.dialogueid group (a.dialogueid)) dates on dates.maxcreatedate = e.createdate , dates.dialogueid = d.dialogueid group d.configurationid ) d on d.configurationid = c.configurationid c.organisationunitid = '1234' order configurationdescription
by reading articles , question on came query query giving wrong figures, , taking long run.
can please me, doing wrong?
(from c in this.context.vvconfiguration join p in ( d in this.context.dialogue join e in this.context.exchange on d.dialogueid equals e.dialogueid ex exd in ex.defaultifempty() join ec in this.context.exchangeclaimant on exd.exchangeid equals ec.exchangeid exc exec in exc.defaultifempty() join date in ( di in this.context.dialogue join x in this.context.exchange on di.dialogueid equals x.exchangeid join xc in this.context.exchangeclaimant on x.exchangeid equals xc.exchangeid group xc new { di.dialogueid } dates select new { maxdate = dates.max(a => a.exchange.createdate) } ) on exec.exchange.createdate equals date.maxdate xc xec in xc.defaultifempty() group exec new { d.configurationid } g select new { configurationid = g.key.configurationid, enrolment = g.sum(a => ((a.exchange.dialogue.dialoguestatusid == 1 && a.exchange.dialogue.processtypeid == 1) ? 1 : 0)), accepts = g.sum(a => ((acceptsverficationlist.contains(a.verificationdecisionid) && a.exchange.dialogue.processtypeid == 2) ? 1 : 0)), rejects = g.sum(a => ((a.verificationdecisionid == 6 && a.exchange.dialogue.processtypeid == 2) ? 1 : 0)), incomplete = g.sum(a => (a.exchange.dialogue.dialoguestatusid == 4) ? 1 : 0) } ) on c.configurationid equals p.configurationid details configuration in details.defaultifempty() c.organisationunitid == new guid(organizationid) orderby c.configurationdescription select new configurationdetails { configurationid = c.configurationid, configurationdescription = c.configurationdescription, enrolment = configuration.enrolment, accepts = configuration.accepts, rejects = configuration.rejects, incomplete = configuration.incomplete }).tolist();
i unsure of circumstances 'correct' solution create stored procedure, , call instead of composing linq statement.
here article how it
Comments
Post a Comment