亚音速数据集排序顺序

时间:2012-08-08 10:18:03

标签: asp.net datagrid subsonic

我已经高于我的理解水平,但有一个简单的请求来改变.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 Walsh的评论,我试过这个:

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:    }

1 个答案:

答案 0 :(得分:0)

不记得2.1-2.2-2.3中的确切差异,但这会为你编译吗?

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