2012-08-08 100 views
1

我在这里达到了我的理解水平,但有一个简单的请求来更改.NET数据网格中数据的排序顺序。该系统似乎使用SubSonic来执行数据库查询,因此存在抽象层次,我只是不明白,似乎无法猜测;)。亚音速数据集排序顺序

有一个在.aspx文件这样的GridView控件下一条线:

<asp:ObjectDataSource ID="odsCsvReport" runat="server" SelectMethod="FetchAll" TypeName="WFlower.CsvReportController"> 
</asp:ObjectDataSource> 

我搜索的项目“CsvReportController”并且在App_Code文件一个文件名为“CsvReportController.cs”其中有这样一类:

[DataObjectMethod(DataObjectMethodType.Select, true)] 
    public CsvReportCollection FetchAll() 
    { 
     CsvReportCollection coll = new CsvReportCollection(); 
     Query qry = new Query(CsvReport.Schema); 
     //qry.OrderDesc("CsvReportID"); 
     coll.LoadAndCloseReader(qry.ExecuteReader()); 
     return coll; 
    } 

现在,我只是不知道如何得到这个数据由“CsvReportID”字段中降序排序(目前它的上升)。

任何人都可以对此有所了解。就像我说的,我在这里太深了,但它应该是一件小事,我决心要做到底!

谢谢大家!

编辑: 好了,按以下@Mike沃尔什的评论,我想这个代替:

var qry = new Select().From(CsvReport.Schema); 
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); 
return qry.ExecuteAsCollection<CsvReportCollection>(); 

然而现在,这将引发其他地方完全不同的错误:

Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'. 
The statement has been terminated. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'. 
The statement has been terminated. 

Source Error: 

Line 187:  //Do database management. 
Line 188:  int removedUsers = SPs.Hg_DeleteInactiveUsers(14).Execute(); 
Line 189:  int removedOrders = SPs.Hg_DeleteInactiveOrders(14).Execute(); 
Line 190: } 
+0

你使用什么版本?看起来像2.3 – Aristos 2012-08-08 10:23:40

+0

我认为它是2.1。 – Dan 2012-08-08 10:25:33

+0

不记得在2.1-2.2-2.3中的确切区别,但是这会为你编译吗? var qry = new Select()。From(CsvReport.Schema); qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); return qry.ExecuteAsCollection (); – 2012-08-08 23:12:59

回答

0

灿”不要忘记2.1-2.2-2.3中的确切区别,但是这会为你编译吗?

var qry = new Select().From(CsvReport.Schema); 
    qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); 
    return qry.ExecuteAsCollection<CsvReportCollection>();