我一直在尝试将此 T-SQL 代码转换为 EF,但运气不佳。任何帮助都会很棒。
SELECT
Prev2.ContinuedMeetingId AS PreviousValue
FROM
[Meeting] This
OUTER APPLY
(SELECT
prev.ContinuedMeetingId
FROM
[Meeting] prev
WHERE
Prev.ContinuedMeetingId < This.MeetingId) Prev2
WHERE
This.MeetingId = 2710
EF / Linq:
var query1 = (from m in db.Meetings
where m.MeetingId == MeetingId
select new
{
m,
SubName = db.Meetings
.Where(s => m.MeetingId == s.MeetingId)
.Select(s => s.ContinuedMeetingId)
}).ToList();
我想你会想要这样的东西:
var query1 = (from m in db.Meetings
where m.MeetingId == MeetingId
select new
{
m.MeetingId,
db.Meetings
.FirstOrDefault(s => m.MeetingId == s.ContinuedMeetingId)
?.ContinuedMeetingId
}).ToList();