SubSonic Collection Top 1
Asked Answered
M

1

6

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();
Michaeu answered 20/11, 2008 at 17:1 Comment(0)
F
9

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!

Fatherhood answered 20/11, 2008 at 17:37 Comment(2)
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.BusinessMichaeu
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>();Michaeu

© 2022 - 2024 — McMap. All rights reserved.