EntityDataSource OrderBy发生冲突

编程入门 行业动态 更新时间:2024-10-27 04:30:14
本文介绍了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发生冲突

本文发布于:2023-10-22 09:19:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1517097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发生冲突   EntityDataSource   OrderBy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!