我有以下SQL查詢:LINQ到不斷的sql返回null
SELECT DISTINCT
Participant.BackgroundTrainingID,
Location.TrainingSite
FROM Registration, ProgramLocation, Participant, Program, Location
WHERE ProgramLocation.LocationID = Location.LocationID
AND ProgramLocation.ProgramID=Registration.ProgramID
AND Registration.ParticipantID=Participant.ParticipantId
我寫了下面的LINQ to SQL以符合上面的查詢:
var trainingsiteinfo = (from c in db.ProgramLocations
from n in db.Registrations
from l in db.Participants
from h in db.Locations
where c.LocationID == h.LocationID
&& c.ProgramID == n.ProgramID
&& n.ParticipantID == l.ParticipantId
select new {
h.TrainingSite,
l.BackgroundTrainingID }).Distinct();
SQL查詢工作正常,但LINQ不斷返回null。
你是什麼意思的「返回null」? 'Distinct'不返回'null'。但是它可以返回一個空的枚舉,並且你的代碼可以拋出一個'NullReferenceException'。你的意思是其中之一? –
我想我的調試部分在測試時是不正確的,只是修復了幫助文件 –