5

我需要调用一个公开动作的服务器。此操作具有复杂类型集合的字符串或复杂类型集合作为参数。我也需要打电话。

元数据是:

任何一个:

<Action Name="BulkChange" IsBound="true">
<Parameter Name="bindingParameter" Type="Collection(PropertyCore.InspectionDuty)"/>
<Parameter Name="Comment" Type="Edm.String" Unicode="false"/>
<Parameter Name="Changes" Type="Collection(PropertyCore.InspectionDutyChange)"/>
</Action>

具有以下复杂类型:

<ComplexType Name="InspectionDutyChange">
<Property Name="Operation" Type="Operations.Operations" Nullable="false"/>
<Property Name="Identity" Type="Edm.Guid" Nullable="false"/>
<Property Name="IsDisabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="SeriesStart" Type="Edm.DateTimeOffset"/>
<Property Name="Interval" Type="Common.Interval"/>
<NavigationProperty Name="Module" Type="PropertyCore.Module"/>
<NavigationProperty Name="Equipment" Type="PropertyCore.Equipment"/>
<NavigationProperty Name="OperatorTask" Type="PropertyCore.OperatorTask"/>
</ComplexType>

或者,或者:

<Action Name="BulkChange" IsBound="true">
<Parameter Name="bindingParameter" Type="Collection(PropertyCore.InspectionDuty)"/>
<Parameter Name="Updates" Type="PropertyCore.InspectionDutyChanges"/>
</Action>

复杂类型定义为

<ComplexType Name="InspectionDutyChanges">
<Property Name="Comment" Type="Edm.String"/>
<Property Name="Changes" Type="Collection(PropertyCore.InspectionDutyChange)"/>
</ComplexType>

<ComplexType Name="InspectionDutyChange">
<Property Name="Operation" Type="Operations.Operations" Nullable="false"/>
<Property Name="Identity" Type="Edm.Guid" Nullable="false"/>
<Property Name="IsDisabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="SeriesStart" Type="Edm.DateTimeOffset"/>
<Property Name="Interval" Type="Common.Interval"/>
<NavigationProperty Name="Module" Type="PropertyCore.Module"/>
<NavigationProperty Name="Equipment" Type="PropertyCore.Equipment"/>
<NavigationProperty Name="OperatorTask" Type="PropertyCore.OperatorTask"/>
</ComplexType>

我认为没有办法解决这个问题,因为我们必须一次支持多个更新。

我得到的例外都指向 odata.net 中的严重缺陷。

第一个变体:

    Microsoft.OData.ODataException: Unsupported primitive type.
A primitive type could not be determined for an instance of type 'Api.Odata.InspectionDutyChange'.
    
    Result StackTrace:
    at Microsoft.OData.ValidationUtils.ValidateIsExpectedPrimitiveType(Object value,
IEdmPrimitiveTypeReference valuePrimitiveTypeReference,
IEdmTypeReference expectedTypeReference)
    at Microsoft.OData.JsonLight.ODataJsonLightValueSerializer.WritePrimitiveValue(Object value,
IEdmTypeReference actualTypeReference,
IEdmTypeReference expectedTypeReference)
    at Microsoft.OData.JsonLight.ODataJsonLightCollectionWriter.WriteCollectionItem(Object item,
IEdmTypeReference expectedItemType)
    at Microsoft.OData.ODataCollectionWriterCore.InterceptException(Action action)
at Microsoft.OData.TaskUtils.GetTaskForSynchronousOperation(Action synchronousOperation)
    --- End of stack trace from previous location where exception was thrown ---

第二个变体:

Microsoft.OData.ODataException: The parameter 'Updates' is of Edm type kind 'Complex'. You cannot call WriteValue on a parameter that is not of Edm type kinds 'Primitive', 'Enum' or 'Complex'.
    
Stack trace:

Result StackTrace:
at Microsoft.OData.ODataParameterWriterCore.VerifyCanWriteValueParameter(Boolean synchronousCall, String parameterName, Object parameterValue)
at Microsoft.OData.ODataParameterWriterCore.WriteValueAsync(String parameterName, Object parameterValue)

我可以为一个更新制定一个解决方法——但这通常不可用。

我们使用 Odata 客户端,但这不是客户端的问题。堆栈跟踪指向 Odata.Net 堆栈中的限制。更新速度也很慢。替代方案我将不得不手动为这些调用创建 HTTP 请求。

更新:没有解决方法。看起来在 Odata.Net 库中修复此问题之前,我们必须坚持使用标准 REST API 并手动构建有效负载。每个复杂类型都失败了,我无法分解最后一层,因为它包含导航属性。我无法重构参考。我已经在使用自定义反序列化器,因为这是 Odata.Net 中另一个不受支持的场景。除非有人有解决方法,否则此操作与 Odata 兼容,但与 Odata.net 不兼容。

4

1 回答 1

1

我假设您正在使用Simple.Odata.client. 由于在 OData 核心中进行了更改以考虑与实体类型相同的复杂类型,因此该库尚未更新,因为复杂类型具有与实体类型一样的导航属性。可以在此处找到更改描述:ODataComplexValue该问题也已在 GitHub 问题中得到解决:复杂类型集合编写器。因此,我建议您使用Microsoft.OData.Client最新且有效的。

于 2020-02-25T06:54:57.253 回答