2016-07-28 8 views
-2
SELECT * 
FROM 
    ProcedureLookup ProcLookup 
    INNER JOIN (SELECT PatientProcedures.PP_ProcedureId, COUNT(*) as ProcCount 
       FROM (PatientProcedures INNER JOIN Treatments ON PatientProcedures.PP_TreatmentId = Treatments.TS_TreatmentId) 
       WHERE YEAR(Treatments.TS_Date) = YEAR(GETDATE()) 
       GROUP BY PatientProcedures.PP_ProcedureId) cyearProc ON ProcLookup.PL_ProcedureId = cyearProc.PP_ProcedureId 
ORDER BY ProcCount DESC; 

ここでProcedureLookup,Treatments,PatientProceduresは表です。このクエリをLINQに変換するにはどうすればよいですか?

+0

何か試しましたか?あなたのコードを共有できますか? –

答えて

0

ここでは、linqクエリです。

var result = (from ProcLookup in db.ProcedureLookup 
      join cyearProc in (
            from p in db.PatientProcedures 
            join t in db.Treatments on p.PP_TreatmentId equals 
                  t.TS_TreatmentId 
            where 
            t.TS_Date.Year == DateTime.Now.Year 
            group p by p.PP_ProcedureId into 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(); 
+1

私はいくつかの変更を加えるときあなたの貴重な時間ありがとう – aNTONY

関連する問題