使用group by将Linq转换为SQL

使用group by将Linq转换为SQL,sql,vb.net,linq,linq-to-sql,linq-group,Sql,Vb.net,Linq,Linq To Sql,Linq Group,如何在linq VB.NET中编写此查询 select top 15 count(1), A.Latitude, A.Longitude from Bairro A inner join Empresa B on B.BairroID = A.BairroID where A.CidadeID = 4810 group by A.Latitude, A.Longitude order by COUNT(1) desc 我找到了这个密码: Dim TopBairros = (From A In

如何在linq VB.NET中编写此查询

select top 15 count(1), A.Latitude, A.Longitude
from Bairro A
inner join Empresa B on B.BairroID = A.BairroID
where A.CidadeID = 4810
group by A.Latitude, A.Longitude
order by COUNT(1) desc
我找到了这个密码:

Dim TopBairros = (From A In Bairros _
                  Join B In New BO.Empresa().Select On B.BairroID Equals A.BairroID Group A By A.Latitude, A.Longitude Into g = Group _
                  Select g Distinct _
                  Order By g.Count Descending).Take(15)
每行都有一个数组集合,其中重复包含具有计数编号的相同对象。例如:

第0行:874个相同对象的数组 第1行:710个相同对象的数组

等等。。。如何才能每行只返回一个对象?

尝试以下操作:

var query = from a in context.Bairro
            where a.CidadeID == 4810
            join b in context.Empresa on a.BairroID equals b.BairroID
            group a by new { a.Latitude, a.Longitude } into grouped
            orderby grouped.Count() descending
            select new { grouped.Key.Latitude,
                         grouped.Key.Longitude,
                         Count = grouped.Count() };
var top15 = query.Take(15);
试试这个:

var query = from a in context.Bairro
            where a.CidadeID == 4810
            join b in context.Empresa on a.BairroID equals b.BairroID
            group a by new { a.Latitude, a.Longitude } into grouped
            orderby grouped.Count() descending
            select new { grouped.Key.Latitude,
                         grouped.Key.Longitude,
                         Count = grouped.Count() };
var top15 = query.Take(15);

我正在使用VB.NET。。。我找到了这个代码:Dim-TopBairros=(从Bairros中的A加入到新的BO.Empresa()中。在B.BairroID上选择等于A.BairroID组A乘以A.纬度,A.经度到g=组u选择g不同u.顺序乘以g.计数递减)。取(15)每行都有一个数组集合,其中重复包含具有计数编号的相同对象。示例:第0行:874个相同对象的数组第1行:710个相同对象的数组,依此类推。。。如何才能每行只返回一个对象?@Fernando:使用我在末尾得到的投影-选择组的键和计数。我使用的是VB.NET。。。我找到了这个代码:Dim-TopBairros=(从Bairros中的A加入到新的BO.Empresa()中。在B.BairroID上选择等于A.BairroID组A乘以A.纬度,A.经度到g=组u选择g不同u.顺序乘以g.计数递减)。取(15)每行都有一个数组集合,其中重复包含具有计数编号的相同对象。示例:第0行:874个相同对象的数组第1行:710个相同对象的数组,依此类推。。。如何才能每行只返回一个对象?@Fernando:使用我在末尾得到的投影-选择组的键和计数。