将SQL内连接,分组依据和顺序转换为LINQ

时间:2017-05-26 10:02:10

标签: sql-server vb.net linq

我创建了一个SQL查询,如下所示:

SELECT s.FullName, s.[Id], COUNT(t.[User]) AS Records
FROM dbo.AspNetUsers s INNER JOIN dbo.PBBuilds t
ON s.Id = t.[User]
GROUP BY t.[User], s.[FullName], s.[Id]
ORDER BY COUNT(t.[User]) DESC

我试图将其转换为LINQ查询,这就是我有多远:

Dim results = From H In context.Users
           Join C In context.PBBuilds On H.Id Equals C.User
           Group By C.User Into

有人可以提供建议吗。

2 个答案:

答案 0 :(得分:1)

尝试此查询 - (尽管做出相应的更改)

$(".tbody").load(location.href+" .tbody > *",function(){
$.getScript("js/highlight.min.js"); 
});

答案 1 :(得分:0)

尝试代码

var results = From U In context.AspNetUsers
   Join P In context.PBBuilds On U.Id Equals P.User
   Group new {U,P} By new { P.User, U.FullName } Into g       
   select new {
     FullName = g.FirstOrDefault().U.FullName,
     ID = g.FirstOrDefault().U.Id,
     Records = g.Count()
   }).OrderByDescending(c=>c.Records).ToList();