【发布时间】:2012-08-05 10:30:43
【问题描述】:
我在这里的理解水平远远超出我的理解水平,但有一个简单的请求来更改 .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: }
【问题讨论】:
-
你用的是什么版本?看起来像 2.3
-
不记得 2.1-2.2-2.3 中的确切差异,但可以为您编译吗? var qry = new Select().From(CsvReport.Schema); qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); return qry.ExecuteAsCollection
(); -
谢谢 Mike,我已经更新了主帖,并在执行此操作时抛出了错误消息...
-
好吧,您已经解决了 SubSonic 问题,但现在您遇到了 SQL 问题。 SPs 前缀是标准 SQL 存储过程的挂钩,因此您必须查看 Hg_DeleteInactiveOrders 实际执行的操作。一个疯狂的猜测是有一个计划的清理任务,并且在它运行之前你已经运行了两次删除 SP。解决方法是将查询从 Delete SP 复制到 SSMS,更改为 SELECT,查看它找到什么并从 OrdersToDelete 表中删除欺骗?我将发布我的第一条评论作为答案。如果快速修复不起作用,将第二个问题作为新问题发布,这可能会很棘手。