我需要有多個左連接的LINQ查詢的幫助。這是LINQ到EF4。我編寫了SQL並將其轉換爲LINQ,但不知道LINQ中的'連接'是內部連接。我已經看過所有的例子,但只能找到一個左連接的例子。任何幫助深表感謝!LINQ查詢中的多個左連接C#
這裏的SQL:
SELECT
s.FirstName, s.LastName, s.StakeholderID, op.ParticipantID, op.SchoolID, oc.CycleNumber,
st.SessionTypeID, st.SessionDescription, CONVERT(varchar(10),os.SessionDt,101) AS SessionDTrr,
os.OSStatus, oee.EvaluatorID
FROM
Stakeholders s LEFT JOIN ObservationParticipants op ON s.StakeholderID = op.StakeholderID
LEFT JOIN ObservationEvaluateeEvaluators oee ON op.ParticipantID = oee.EvaluateID
LEFT JOIN ObservationCycles oc ON oee.ObservationEvaluateeEvaluatorID = oc.ObservationEvaluateeEvaluatorID
LEFT JOIN ObservationSessions os ON oc.ObservationCycleID = os.ObservationCycleID
LEFT JOIN SessionTypes st ON os.SessionTypeID = st.SessionTypeID
WHERE
oee.EvaluatorID = evaluatorID
下面是我轉換了上述說法太LINQ。儘管我需要連接。任何人都可以協助將LINQ中的連接轉換爲左連接嗎?
from s in Stakeholders
join op in ObservationParticipants
on s.StakeholderID equals op.StakeholderID
join oee in ObservationEvaluateeEvaluators
on op.ParticipantID equals oee.EvaluateID
join oc in ObservationCycles
on oee.ObservationEvaluateeEvaluatorID equals oc.ObservationEvaluateeEvaluatorID
join os in ObservationSessions
on oc.ObservationCycleID equals os.ObservationCycleID
join st in SessionTypes
on os.SessionTypeID equals st.SessionTypeID
where oee.EvaluatorID == evaluatorID
select new {
s.FirstName, s.LastName, s.StakeholderID,
op.ParticipantID, op.SchoolID, oc.CycleNumber,
st.SessionTypeID, st.SessionDescription, os.SessionDt,
os.OSStatus
}
http://codingsense.wordpress.com/2009/03/08/left-join-right-join-using-linq/ - 我希望,你可以幫忙 – sinanakyazici
如果你正確設置LinqPad,可以根據您當前的查詢生成linq查詢。 – MethodMan
我實際上使用LinqPad創建上面的LINQ查詢。我不認爲LinqPad可以將SQL轉換爲LINQ。 – EFX