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

1 回答 1

0

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

    var qry = new Select().From(CsvReport.Schema); 
    qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); 
    return qry.ExecuteAsCollection<CsvReportCollection>();
于 2012-08-09T14:02:56.043 回答