我正在尝试将这个相当复杂的(从我的角度来看,因为我不处理 SQL)查询转换为 LINQ:
SELECT f.description,
s.description,
file_no,taskid,
h.description
from_userid,
userid,
h.starttime,
locktime,
lockby,
h.status,
h.endtime
FROM history h
INNER JOIN flowdefinition f on h.flowid = f.flowid
INNER JOIN stepdefinition s on h.flowid = s.flowid and h.stepid = s.stepid
WHERE taskid = 'SERVER2012_03_08_09_31_40_367'
AND h.status in ('R','U','C','K')
AND h.flowid not in (999)
order by endtime
这就是我到目前为止所拥有的:
var resultList = from h in context.History_master
join f in context.flowdefinition_master on new { h.flowid, h.LocId } equals new { f.flowid, f.LocId } into hf
from h in hf.DefaultIfEmpty()
join s in context.stepdefinition_master on new { h.stepid, h.LocId } equals new { s.stepid, s.LocId } into hs
from s in hs.DefaultIfEmpty()
where h.file_no == fileNumber
orderby h.endtime
select new
{
};
但这抱怨“范围变量'h'与'h'的先前声明冲突。我知道它说它就像第二个声明,但我不知道我会如何在LINQ中做到这一点。任何帮助有了这个(完整或部分:))将不胜感激!
//编辑:
如果我按照建议更改
from h in hf.DefaultIfEmpty()
为from h1 in hf.DefaultIfEmpty()
,则 h1 不具有与 h 相同的属性。所以我不能做第二次加入,因为桌子不在那里......