views:

476

answers:

2

I'm using Subsonic 3.0.0.3 for a new project and on one of my pages I'm wanting to display only 5 records that are the top 5 read records. My SQL select statement is

select top(5) * from myTable order by reads desc

Is this possible to do with ActiveRecord? If it is I haven't came across how yet.

Jon

+3  A: 

You can use Take to select a limited number of items for example:

IQueryable<myTable> topFive = myTable.All()
  .OrderByDescending(table => table.reads)
  .Take(5);
Adam
A: 

Using a Subsonic query (as you asked), that would be:

var q = new SubSonic.Query.Select().Top("5")
    .From("myTable")
    .OrderDesc("reads");

List<myTable> collection = q.ExecuteTypedList<myTable>();
Junto