将 T-SQL OUTER APPLY 转换为 EF

问题描述 投票:0回答:1

我一直在尝试将此 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();
entity-framework
1个回答
0
投票

我想你会想要这样的东西:

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();
© www.soinside.com 2019 - 2024. All rights reserved.