WCF 数据服务无法响应包括 orderby 的查询
我有一个数据库视图,我使用 WCF 数据服务将其发布到其他系统。数据库和 WCF 数据服务之间的中间层基于 Entity Framework 4.1 构建
当我使用不带 orderby 的简单查询来查询视图时,我会得到所有结果。如果我包含 orderby 运算符,查询将失败并显示以下错误消息(UseVerboseErrors 设置为 true):
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code />
<message xml:lang="de-DE">An error occurred while processing this request.</message>
- <innererror>
<message>Object reference not set to an instance of an object.</message>
<type>System.NullReferenceException</type>
<stacktrace>at lambda_method(Closure , StatesView ) at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext() at System.Linq.Enumerable.<TakeIterator>d__3a`1.MoveNext() at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService`1.HandleRequest()</stacktrace>
</innererror>
</error>
我做错了什么?该视图在与我想要用于排序的列不同的列上定义了一个数据服务键。
这里是查询:
http://localhost:6000/MyView?$orderby=number desc
I have a database view which I publish to other systems using WCF data services. The middle layer between the database and the WCF Data Services is built upon Entity Framework 4.1
When I query the view using a simple query without orderby, I get all results. If I include the orderby operator, the query fails with following error message (UseVerboseErrors is set to true):
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code />
<message xml:lang="de-DE">An error occurred while processing this request.</message>
- <innererror>
<message>Object reference not set to an instance of an object.</message>
<type>System.NullReferenceException</type>
<stacktrace>at lambda_method(Closure , StatesView ) at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext() at System.Linq.Enumerable.<TakeIterator>d__3a`1.MoveNext() at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService`1.HandleRequest()</stacktrace>
</innererror>
</error>
What do I do wrong? The view has a data service key defined on a column different to this one I want to use for sorting.
Here the query:
http://localhost:6000/MyView?$orderby=number desc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如上面注释中所述,实体集查询根(返回 IQueryable 的属性)返回的枚举不得包含 null 项。如果确实如此,很多事情都会出错,其中之一如上面的问题所示。
As noted in the comments above the enumeration returned by an entity set query root (the property which returns the IQueryable) must not contain null items in it. If it does lot of things will go wrong, one of them being shown in the question above.