WCF数据服务(OData),SetEntitySetPageSize和自定义操作存在问题 [英] Problem with WCF Data Service (OData), SetEntitySetPageSize and custom operations

查看:88
本文介绍了WCF数据服务(OData),SetEntitySetPageSize和自定义操作存在问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF数据服务,该服务带有名为MostRecentFilms的自定义操作,该操作返回源中的10部最新电影.每部影片都具有Year属性.默认设置一切正常,但是当我设置实体集的页面尺寸config.SetEntitySetPageSize("*", 100)时,返回的影片的顺序不好.结果集是否少于100无关紧要,它们没有按照从最近到正确的顺序排序(不存在页面大小限制时如何返回).

I have a WCF Data Service with a custom operation named MostRecentFilms that returns the 10 most recent films in the source. Each film has, among others, a Year property. All goes fine with the default setting but when I set the page size for entity sets, config.SetEntitySetPageSize("*", 100), the order of returned films are not good. Doesn't matter if the result set has less than 100, they are not properly ordered from more recent to less, how it was returned when the page size restriction wasn't present.

我不知道这是WCF数据服务错误还是在这里缺少某些配置.任何有助于澄清这一点的方法将不胜感激.

I don't know if this is a WCF Data Service bug or if I'm missing some configuration here. Any help to clarify this will be appreciated.

推荐答案

这实际上是设计使然.服务器驱动的页面调度(SetEntitySetPageSize启用它)的实现方式需要结果的稳定(众所周知)顺序. 因此,服务将根据给定实体上的所有关键属性对服务操作的结果进行排序(它也对实体集执行此操作). 客户可以在某种程度上影响订购-如果请求上有$ orderby,则结果订单将是$ orderby的应用,后跟所有关键属性. 当前,服务器上没有办法规定实体集或服务操作的顺序,以使得服务器驱动的分页的处理会将其考虑进去,就像处理客户端的$ orderby一样. 您可以让您的客户添加正确的$ orderby,或者如果不可能的话,我能想到的唯一其他解决方法是在WCF Data Service处理$ orderby之前将其注入URL(可以通过自定义主机来完成) ,特殊标头WCF等取决于您对服务的托管方式等.但这有点hacky,要求您半解析URL,以便能够识别已经存在的任何$ order. 请注意,此行为不仅适用于服务器驱动的分页,而且$ top和$ skip还会对结果重新排序以保持稳定的顺序.

This is actually by design. The way the server driven paging (SetEntitySetPageSize enables it) is implemented requires a stable (and well known) order of the results. So the service will order the results of your service operation (it does that with entity sets as well) by all the key properties on the given entity. The client can influence the ordering to some extent - if there's an $orderby on the request the resulting order will be the application of $orderby followed by all the key properties. Currently there's no way on the server to prescribe the order for either entity set or service operation such that the processing of server driven paging would take it into considertation the same way it does with $orderby from the client. You can either make your client add the right $orderby or if that's not possible the only other workaround I can think of is to inject the $orderby into the URL before it gets processed by WCF Data Service (this can be done through a custom host, special headers, WCF, ... depends on how exactly you host the service and such). But that's a bit hacky and requires you to semi-parse the URL to be able to recognize any existing $orderby already there. Note that this behavior is not only for server driven paging, also $top and $skip will reorder the results to maintain a stable ordering.

这篇关于WCF数据服务(OData),SetEntitySetPageSize和自定义操作存在问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆