Converting SQL containing top, count, group and order to LINQ (2 Entities)

后端 未结 2 1152
春和景丽
春和景丽 2020-12-21 01:08

Some LINQ queries still puzzle me.

for a table \'Hits\' containing two columns, \'Page\' and \'Date\', I want to find the most Pages with the most rows in a defined

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 01:45

    Something like this should work:

    (from p in DataContext.Hits
    where (p.Date >= minDate) && (p.Date < maxDate)
    group p by p.Page into g
    select new { Page = g.Key, Number = g.Count() }).OrderByDescending(x => x.Number).Take(10);
    

提交回复
热议问题