Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SubSonic Collection Top 1

Is there way in next piece of code to only get the first record?

Dal.TreeHtmlExportsCollection treeHtmlExportsCollection =
  new Dal.TreeHtmlExportsCollection().Where(Dal.TreeHtmlExports.Columns.TreeId, treeId).
  OrderByDesc(Dal.TreeHtmlExports.Columns.DateCreated).Load();
like image 276
Lieven Cardoen Avatar asked Nov 20 '08 17:11

Lieven Cardoen


1 Answers

You can do this using the Query tool like so: (requires SubSonic 2.1)

var query = new Select()
     .Top("1")
     .From(TreeHtmlExports.Schema)
     .Where(TreeHtmlExports.Columns.TreeId).IsEqualTo(treeId)
     .OrderDesc(TreeHtmlExports.Columns.DateCreated);

treeHtmlExportCollection = query.ExecuteAsCollection<TreeHtmlExportsCollection>();

Hope that helps!

like image 68
remotefacade Avatar answered Oct 10 '22 11:10

remotefacade