CRM 2016 oData 扩展收集
CRM 2016 oData expand on collection
我正在尝试从新的 REST API 检索多个数据,但我遇到了一个奇怪的问题。如果我在一个集合上使用 $expand 那么它就不起作用。
请求是:
GET [Oranization URL]/api/data/v8.0/accounts?$expand=contact_customer_accounts HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
响应:
{
"error": {
"code": "",
"message": "Expansion of navigation properties isn\u2019t supported on entity collections.",
"innererror": {
"message": "Expansion of navigation properties isn\u2019t supported on entity collections.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ThrowIfSelectClauseHasNavigationProperty(SelectExpandClause selectExpandClause, Boolean isCalledFromEntitySet)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
但如果我对单个实体发出此请求,那么我会得到结果
[Organization URL]/api/data/v8.0/accounts(9761dd37-d1b6-e511-80d7-001dd8b71fde)?$expand=contact_customer_accounts
在以前的 CRM 版本(2011、2015)中,这是完美的。 MS有可能删除这个功能吗?实际上,oData 4.0 协议允许这种类型的查询
http://services.odata.org/v4/TripPinServiceRW/People?$expand=Trips
为什么 MS 不允许它?没有这个,新的 REST API 就没用了。
尽管我希望这会在 Microsoft Dynamics CRM Web API Limitations 中列出,但它确实似乎是当前实施的限制。
其他用户和您一样注意到 it appears that the $expand clause only works when requesting data of a single record。
我提出了一个建议,该建议已作为 Spring 2016 版 CRM 的一部分实施:Web API: Implement $expand on collections:
We enabled this capability in Spring 2016 release of Dynamics CRM. If
you request an expand & select on a related collection the response
will contain an empty collection with a nextlink which you can then
use to programmatically request each of the related pages. We are
actively looking into how we can support $filter on the expanded
collection. If your scenario requires that then please create another
idea so that it we can prioritize it accordingly.
我正在尝试从新的 REST API 检索多个数据,但我遇到了一个奇怪的问题。如果我在一个集合上使用 $expand 那么它就不起作用。
请求是:
GET [Oranization URL]/api/data/v8.0/accounts?$expand=contact_customer_accounts HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
响应:
{
"error": {
"code": "",
"message": "Expansion of navigation properties isn\u2019t supported on entity collections.",
"innererror": {
"message": "Expansion of navigation properties isn\u2019t supported on entity collections.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ThrowIfSelectClauseHasNavigationProperty(SelectExpandClause selectExpandClause, Boolean isCalledFromEntitySet)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
但如果我对单个实体发出此请求,那么我会得到结果
[Organization URL]/api/data/v8.0/accounts(9761dd37-d1b6-e511-80d7-001dd8b71fde)?$expand=contact_customer_accounts
在以前的 CRM 版本(2011、2015)中,这是完美的。 MS有可能删除这个功能吗?实际上,oData 4.0 协议允许这种类型的查询
http://services.odata.org/v4/TripPinServiceRW/People?$expand=Trips
为什么 MS 不允许它?没有这个,新的 REST API 就没用了。
尽管我希望这会在 Microsoft Dynamics CRM Web API Limitations 中列出,但它确实似乎是当前实施的限制。
其他用户和您一样注意到 it appears that the $expand clause only works when requesting data of a single record。
我提出了一个建议,该建议已作为 Spring 2016 版 CRM 的一部分实施:Web API: Implement $expand on collections:
We enabled this capability in Spring 2016 release of Dynamics CRM. If you request an expand & select on a related collection the response will contain an empty collection with a nextlink which you can then use to programmatically request each of the related pages. We are actively looking into how we can support $filter on the expanded collection. If your scenario requires that then please create another idea so that it we can prioritize it accordingly.