0

I have a T-SQL query

SELECT *
FROM BPM.tblEvaluationCatalogPlan
JOIN BPM.tblEvaluationCatalog ON BPM.tblEvaluationCatalogPlan.EvaluationCatalogId =
BPM.tblEvaluationCatalog.EvaluationCatalogId
JOIN BPM.tblMeasureProcess ON BPM.tblEvaluationCatalog.MeasureProcessId =
BPM.tblMeasureProcess.MeasureProcessId
JOIN dbo.tblMeasureCatalog ON BPM.tblMeasureProcess.MeasureCatalogId =
dbo.tblMeasureCatalog.MeasureCatalogId
LEFT OUTER JOIN dbo.tblMeasureUnit ON dbo.tblMeasureCatalog.MeasureUnitId =
dbo.tblMeasureUnit.MeasureUnitId

And I've written a LINQ Query for it

from m in tblEvaluationCatalogPlan
join l in tblEvaluationCatalog.Where(y => y.PlanId == PlanId) on
m.EvaluationCatalogId equals l.EvaluationCatalogId
join k in tblMeasureProcess.Where(x => x.ProcessId == ProcessId) on
l.MeasureProcessId equals k.MeasureProcessId
join j in tblMeasureCatalog on k.MeasureCatalogId equals
j.MeasureCatalogId
join i in tblMeasureUnit on j.MeasureUnitId equals i.MeasureUnitId
select new EvaluationCatalogPlanEntity
   {
   EvaluationCatalogPlan = m,
   EvaluationCatalog = l,
   MeasureProcess = k,
   MeasureCatalog = j,
   MeasureUnit = i
   }

But Their output aren't the same.

What is the exact equivalent of the T-SQL Query in LINQ?

codeWorm
  • 51
  • 9

2 Answers2

0

you should put code in the code format so it's easier to read.

I have been able to achieve this result with group joins. Take a look here: http://msdn.microsoft.com/en-us/library/bb397895(v=vs.120).aspx

Should be possible to get what it seems you are looking for.

0

Try http://msdn.microsoft.com/en-US/vstudio/ee908647.aspx#leftouterjoin

 var leftFinal =
    from l in lefts
    join r in rights on l equals r.Left into lrs
    from lr in lrs.DefaultIfEmpty()
    select new { LeftId = l.Id, RightId = ((l.Key==r.Key) ? r.Id : 0 };
Naveen Kumar
  • 1,541
  • 10
  • 12