WCF 数据服务无法响应包括 orderby 的查询

发布于 2024-12-09 20:39:03 字数 1473 浏览 0 评论 0原文

我有一个数据库视图,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2024-12-16 20:39:03

如上面注释中所述,实体集查询根(返回 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文