2

我将 EntityDataSource 与 RadGrid 一起使用。我在将 EntityDataSource“OrderBy”与“Select Top”语句组合在一起时遇到问题。

<asp:EntityDataSource runat="server" 
                      ID="EntityDataSourceAlarm"
                      ConnectionString="name=AlarmEntities" 
                      DefaultContainerName="AlarmEntities" 
                      EnableFlattening="False" 
                      EntitySetName="Alarms" 
                      OrderBy="it.Status ASC, it.TS DESC" 
                      Select="top(10) it.[OID], it.[TS], it.[Status]">
</asp:EntityDataSource>

我希望在select 子句之前应用 order by 子句。top(10)当省略select 子句的 " " 部分时,这一切都有效。它应该首先按 [Status] 排序,然后按 [TS] 排序。然后在 select 语句中使用 top ,似乎它丢弃了 order by 子句。

我正在使用 .Net 4.5 和 EntityFramework 5。

4

1 回答 1

1

这是一个解决方案,我对性能持怀疑态度,但效果很好:

<asp:EntityDataSource 
ID="edsHighUsage" 
runat="server" 
ConnectionString="name=DbEntities" 
DefaultContainerName="DbEntities" 
EnableFlattening="False" 
EntitySetName="HighUsages" 
OnSelecting="edsHighUsage_Selecting" 
OrderBy="it.MonthlyCost desc"
Select="it.[PhoneNumber], it.[MonthlyCost]">
</asp:EntityDataSource>

代码隐藏:

protected void edsHighUsage_Selecting(object sender, EntityDataSourceSelectingEventArgs e)
{
    e.SelectArguments.MaximumRows = 100;
}  
于 2014-08-18T04:24:45.527 回答