我有一个T-SQL查询
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
我已经为它编写了一个LINQ查询
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
}
但他们的输出并不相同。
LINQ中T-SQL查询的确切等价物是什么?
答案 0 :(得分:0)
您应该将代码放入代码格式,以便于阅读。
我已经能够通过群组连接实现此结果。看看这里: http://msdn.microsoft.com/en-us/library/bb397895(v=vs.120).aspx
应该可以获得您正在寻找的东西。
答案 1 :(得分:0)
尝试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 };