EntityDataSource OrderBy conflict

戏子无情 提交于 2019-12-24 01:43:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!