$ expand =在OData版本4中失败

时间:2019-02-16 17:25:24

标签: odata

对于OData版本4查询(已编辑的部分):

  

https://myurl/PROTEIN_LOT?$ filter =(条形码eq'PRO27-1')&$ expand = PROJECT

我遇到了例外情况:

  

Microsoft.OData.Core.ODataException:'在编写JSON响应时,必须指定用户模型,并且必须将实体集和实体类型传递给ODataMessageWriter.CreateODataEntryWriter方法,或者必须在ODataEntry上设置ODataFeedAndEntrySerializationInfo或正在写入的ODataFeed。'

这是第二次reader.State为ODataReaderState.NavigationLinkStart,其中对navLink.Url的调用将引发异常。第一次迭代很好,它返回了正确的URI。

如果$ expand =不在请求中,则它可以正常工作。我们正在使用Microsoft.Data.OData 5.6.3.0。

(尝试简化为仅键控代码):

ODataMessageReaderSettings settings = new ODataMessageReaderSettings { MessageQuotas = { MaxReceivedMessageSize = maxMessageSize } };
ODataMessageReader messageReader = new ODataMessageReader(responseMessage, settings, model);

while (reader.Read())
    switch (reader.State)
    {
        case ODataReaderState.NavigationLinkStart:
            ODataNavigationLink navLink = (ODataNavigationLink)reader.Item;
            navName = navLink.Name;
            if (resultEntryOn != null && string.IsNullOrEmpty(resultEntryOn.UriEntry))
            {
                // ERROR HERE - the second time it's called
                string urlentry = navLink.Url.AbsoluteUri;
                resultEntryOn.UriEntry = urlentry.Substring(0, urlentry.LastIndexOf("/"));
            }
            break;

        // other case items - all work

0 个答案:

没有答案