1

我是 Linq 世界的新手,由于数据库中的一些约束影响添加我需要的一些字段,我无法弄清楚如何将以下 sql 转换为 linq:

select sp.SessionID,
    sp.SessionParticipationID,
    case when z.SessionParticipationID = sp.SessionParticipationID then 1 else 0 end as RecordedFL
from SessionParticipation sp
inner join (
    select sp1.SessionID,
        sp1.SessionParticipationID
    from Meeting.SessionParticipation sp1
    inner join RegistrantActivity ra on ra.SessionParticipationID = sp1.SessionParticipationID
    where ra.RegistrantID = 12345
) z on z.SessionID = sp.SessionID

实体是 SessionParticipation 和 RegistrantActivity

4

1 回答 1

1

它应该是这样的

from sp in SessionParticipations
join z in
(from sp1 in MeetingSessionParticipations
join ra in RegistrantActivities on sp1.SessionParticipationID equals 
                                   ra.SessionParticipationID
where ra.RegistrantID = 12345
select sp1)
on sp.SessionID equals z.SessionID
select new { 
             sp.SessionParticipationID,
             RecordedFL = z.SessionParticipationID == sp.SessionParticipationID
                          ? 1 : 0
           }

假设它Meeting.SessionParticipation是与 不同模式中的不同表SessionParticipation,否则连接会使事情变得不必要地复杂。(尽管不同模式中的相同表名是......令人困惑)。

于 2012-05-11T20:39:27.683 回答