Linq查询3个表

时间:2017-07-26 14:55:13

标签: c# linq

请告诉我如何为以下SQL查询编写LINQ,

Select cr.Id 
from [dbo].[User] usr, [dbo].[LikesStaging] lk, [dbo].[ChangeRequestStaging] cr 
where usr.CustomerId=lk.[LikedBy] and usr.[Id] = 'user' and lk.[ChangeRequestId] = cr.[Id]

尝试使用以下查询,但无法在我的linq查询中添加usr.[Id] = 'user'条件。

var result = from usr in lstUser
             join lk in lstLikeStaging
             on usr.CustomerId equals lk.LikedBy
             join cr in lstChangeRequests
             on lk.ChangeRequestId equals cr.Id
             select new
             {
                 cr.Id
             };

请告诉我如何在此处添加此条件。

2 个答案:

答案 0 :(得分:0)

var result = from usr in lstUser
join lk in lstLikeStaging on usr.CustomerId equals lk.LikedBy
join cr in lstChangeRequests on lk.ChangeRequestId equals cr.Id
where usr.id=="user"
select new
{
 cr.Id
};

答案 1 :(得分:0)

 var result = from usr in lstUser
                     where usr.Id == "user"
                     join lk in lstLikeStaging
                     on usr.CustomerId equals lk.LikedBy
                     join cr in lstChangeRequests
                     on lk.ChangeRequestId equals cr.Id
                     select new
                     {
                         cr.Id
                     };