How do I convert this query into LINQ? -


select *   procedurelookup proclookup   inner join (select patientprocedures.pp_procedureid, count(*) proccount               (patientprocedures inner join treatments on patientprocedures.pp_treatmentid = treatments.ts_treatmentid)               year(treatments.ts_date) = year(getdate())               group patientprocedures.pp_procedureid) cyearproc on proclookup.pl_procedureid = cyearproc.pp_procedureid order proccount desc; 

here procedurelookup, treatments, patientprocedures tables.

here linq query.

var result = (from proclookup in db.procedurelookup              join cyearproc in (                                   p in db.patientprocedures                                   join t in db.treatments on p.pp_treatmentid equals                                                               t.ts_treatmentid                                                                       t.ts_date.year == datetime.now.year                                   group p p.pp_procedureid g                                   select new                                   {                                     pp_procedureid = g.key,                                     proccount = g.count()                                   }                                ) on proclookup.pl_procedureid equals                                     cyearproc.pp_procedureid              orderby cyearproc.proccount descending              select new              {                 // columns                 pp_procedureid = proclookup.pp_procedureid,                 proccount = cyearproc.proccount              }).tolist(); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -