我有一个SQL查询,如下所示
SELECT ui.PageStyleCss
FROM UserImages ui
WHERE ui.UserImageId IN
( SELECT inv.UserImageId
FROM Invitation inv
JOIN InviteeEmails invEmails ON
inv.InviteID = invEmails.InviteID
WHERE invEmails.InviteGUID = @InviteGUID
)
我怎样才能在LINQ中写这个?
由于
答案 0 :(得分:3)
我猜测你正在使用LINQ to SQL。如果你提到这个,以及你的模型的细节,那将是很好的。猜测它的结构......
var q = from ui in Context.UserImages
where ui.Invitations.Any(i => i.InviteeEmails.Any(e => e.InviteGuid = inviteGuid))
select ui.PageStyleCss;
答案 1 :(得分:0)
from ui in db.UserImages
where (from inv in db.Invitations
join invEmails from InviteeEmails
on inv.InviteId equals invEmails.InviteId
where invEmails.InviteGUID == inviteGUID
select inv.UserImageId).Contains(ui.UserImageId)
select ui.PageStyleCss
(不确定是否编译)
我必须假设有一种更好的方式......这几乎是一种直接翻译。