views:

1150

answers:

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();
+4  A: 

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!

remotefacade
I get this error :Error 2 Property or indexer 'SubSonic.SqlQuery.TopSpec' cannot be assigned to -- it is read only C:\Users\LIC.TELEVIC\_PROJECTS\_TELEVIC\Edumatic3\edumatic-3-framework-server-.NET\Edumatic3.Business\ReportLogic.cs 44 4 Edu3.Business
Lieven Cardoen
var query = new Select().Top("1").From(TreeHtmlExports.Schema).Where(TreeHtmlExports.Columns.TreeId).IsEqualTo(treeId) .OrderDesc(TreeHtmlExports.Columns.DateCreated); Dal.TreeHtmlExportsCollection treeHtmlExportsCollection = query.ExecuteAsCollection<TreeHtmlExportsCollection>();
Lieven Cardoen
This works! thx!
Lieven Cardoen