2008-11-20 72 views
6

在下一段代碼中只有獲得第一條記錄的方法嗎?SubSonic Collection Top 1

Dal.TreeHtmlExportsCollection treeHtmlExportsCollection = 
    new Dal.TreeHtmlExportsCollection().Where(Dal.TreeHtmlExports.Columns.TreeId, treeId). 
    OrderByDesc(Dal.TreeHtmlExports.Columns.DateCreated).Load(); 

回答

9

您可以使用查詢工具,像這樣做:(需要亞音速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>(); 

希望幫助!

+0

我得到這個錯誤: 錯誤屬性或索引 'SubSonic.SqlQuery.TopSpec' 不能被分配到 - 它是隻讀\t C:\用戶\ LIC.TELEVIC \ _PROJECTS \ _TELEVIC \ Edumatic3 \ edumatic3-framework-server-.NET \ Edumatic3.Business \ ReportLogic.cs Edu3.Business – 2008-11-20 18:11:51