このかなり複雑な (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' の以前の宣言と競合します。2 番目の宣言のようなものだと言っていることは理解していますが、LINQ でこれをどのように行うかはわかりません。何か助けてください。これで(完全または部分的:))大歓迎です!
//編集:
提案どおりに変更する
from h in hf.DefaultIfEmpty()
とfrom h1 in hf.DefaultIfEmpty()
、h1 には h と同じプロパティがありません。テーブルがないため、2番目の結合を実行できません...