0

评论表有用户 ID。

select u.userid,review,COUNT(review) as coun,u.firstName,u.lastname,u.avatar,u.userid from reviews r
inner join users u on u.userid=r.userid
group by u.userid,review,u.firstName,u.lastname,u.avatar,u.userid
order by coun desc

这个脚本是如何翻译成linq的?我有以下不工作,不完整的代码。 代码

var reviews = from r in context.Reviews.Where(r => r.CreateDate > dateFrom && r.CreateDate < dateTo)
                              group r by new { r.Review1, r.UserID } into g
                              join u in context.Users on g.Key.UserID equals u.UserID
                              select new UserMan
                              {
                                  ID = u.UserID,
                                  Avatar = u.Avatar,
                                  LastName = u.LastName,
                                  FirstName = u.FirstName,
                                  Review = g.Key.Review1,
                                  Reviews = g.Count()
                              };
                return reviews.ToList();
4

1 回答 1

2

只是摆脱那个加入。

var reviews = from r in context.Reviews.Where(r => r.CreateDate > dateFrom && r.CreateDate < dateTo)
    group r by new { r.Review1, r.User } into g
    select new UserMan
         {
           ID = g.Key.User.UserID,
           Avatar = g.Key.User.Avatar,
           LastName = g.Key.User.LastName,
           FirstName = g.Key.User.FirstName,
           Review = g.Key.Review1,
           Reviews = g.Count()
         };

return reviews.ToList();
于 2013-01-16T19:28:28.280 回答