问题
I'm using an EntityDataSource together with a RadGrid. I have issues with combining an EntityDataSource "OrderBy" together with a "Select Top" statement.
<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>
I want the order by clause to be applied before the select clause. It all works when leaving out the "top(10)
" part of the select clause. It should first sort by [Status] and and then [TS]. Then using top in the select statement, it seems like it discards the order by clause.
I'm using .Net 4.5 and EntityFramework 5.
回答1:
Here is a solution, I was sceptic about performances but it works fine :
<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>
Code-behind :
protected void edsHighUsage_Selecting(object sender, EntityDataSourceSelectingEventArgs e)
{
e.SelectArguments.MaximumRows = 100;
}
来源:https://stackoverflow.com/questions/16164503/entitydatasource-orderby-conflict