odata v4无法在另一个复杂类型中选择复杂类型的属性(使用展开)

时间:2017-04-24 12:41:35

标签: c# json select odata expand

我有一个模型,我有一个项目(根),然后是一个复杂的类型(制造),嵌入另一个复杂类型(位置,名为Factory下面)。

扩展制造业时,所有工作都按预期进行:

https://localhost/Inextrace/Items('ABC123456789')?$select=Code&$expand=Manufacturing($select=Factory)

但是,当我尝试只选择复杂类型位置(Factory)的一个属性时,它表示不支持它。有任何解决方法来实现这个目标吗?

https://localhost/Inextrace/Items('ABC123456789')?$select=Code&$expand=Manufacturing($select=Factory/Code)

响应:

{
  "error":{
    "code":"","message":"The query specified in the URI is not valid. A path within the select or expand query option is not supported.","innererror":{
      "message":"A path within the select or expand query option is not supported.","type":"Microsoft.OData.Core.ODataException","stacktrace":"   at System.Web.OData.Formatter.Serialization.SelectExpandNode.ValidatePathIsSupported(ODataPath path)\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.GetPropertiesToIncludeInQuery(SelectExpandClause selectExpandClause, IEdmEntityType entityType, IEdmEntitySet entitySet, IEdmModel model, ISet`1& autoSelectedProperties)\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.ProjectElement(Expression source, SelectExpandClause selectExpandClause, IEdmEntityType entityType, IEdmEntitySet entitySet)\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.BuildPropertyContainer(IEdmEntityType elementType, Expression source, Dictionary`2 propertiesToExpand, ISet`1 propertiesToInclude, ISet`1 autoSelectedProperties, Boolean isSelectingOpenTypeSegments)\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.ProjectElement(Expression source, SelectExpandClause selectExpandClause, IEdmEntityType entityType, IEdmEntitySet entitySet)\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.GetProjectionLambda()\r\n   at System.Web.OData.Query.Expressions.SelectExpandBinder.Bind(IQueryable queryable)\r\n   at System.Web.OData.Query.SelectExpandQueryOption.ApplyTo(IQueryable queryable, ODataQuerySettings settings, IAssembliesResolver assembliesResolver)\r\n   at System.Web.OData.Query.ODataQueryOptions.ApplySelectExpand[T](T entity, ODataQuerySettings querySettings)\r\n   at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n   at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
    }
  }
}

任何想法只选择工厂的某个领域?

我是C#.Net使用和以下版本的nuget包:

  • Microsoft.AspNet.OData v5.8.0
  • Microsoft.OData.Code v6.14.0
  • Microsoft.AspNet.WebApi v5.2.3

此致 NicolasStübi

0 个答案:

没有答案