0

如何在 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 个相同对象的数组

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

4

1 回答 1

3

尝试这个:

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);
于 2009-12-30T23:15:40.867 回答