本文介绍了EntityDataSource OrderBy发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EntityDataSource和RadGrid.我在将EntityDataSource"OrderBy"与"Select Top"语句组合在一起时遇到问题.

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>

我希望在选择子句之前应用order by子句.忽略select子句的" top(10)"部分时,所有方法均有效.首先应按[状态]排序,然后按[TS]排序.然后在select语句中使用top,似乎它会丢弃order by子句.

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.

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

I'm using .Net 4.5 and EntityFramework 5.

推荐答案

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

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>

隐藏代码:

protected void edsHighUsage_Selecting(object sender, EntityDataSourceSelectingEventArgs e)
{
    e.SelectArguments.MaximumRows = 100;
}

这篇关于EntityDataSource OrderBy发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 16:39