如何在OData打开数据类型上选择$ select?查询无效错误 [英] How to $select on OData Open Data Type? Query not valid error

查看:163
本文介绍了如何在OData打开数据类型上选择$ select?查询无效错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个具有以下类型的开放数据类型的实体服务:

I'm serving an entity that has a Open Data Type of type:

IDictionary

IDictionary

我无法使用$select关键字来选择该词典中的动态数据.我还有$select的其他静态属性.我收到的错误如下:

I'm not able to use the $select keyword to select the dynamic data I have in that dictionary. I have other static atributtes that $select just fine. The error I'm getting is the following:

    {
"error": {
    "code": "",
    "message": "The query specified in the URI is not valid. An identifier was expected at position 0.",
    "innererror": {
        "message": "An identifier was expected at position 0.",
        "type": "Microsoft.OData.ODataException",
        "stacktrace": "   em Microsoft.OData.UriParser.ExpressionToken.GetIdentifier()\r\n   em Microsoft.OData.UriParser.SelectExpandTermParser.ParseSegment(PathSegmentToken previousSegment, Boolean allowRef)\r\n   em Microsoft.OData.UriParser.SelectExpandTermParser.ParseTerm(Boolean allowRef)\r\n   em Microsoft.OData.UriParser.SelectExpandParser.ParseSingleSelectTerm()\r\n   em Microsoft.OData.UriParser.SelectExpandParser.ParseCommaSeperatedSelectList(Func`2 ctor, Func`1 termParsingFunc)\r\n   em Microsoft.OData.UriParser.SelectExpandParser.ParseSelect()\r\n   em Microsoft.OData.UriParser.SelectExpandSyntacticParser.Parse(String selectClause, String expandClause, IEdmStructuredType parentEntityType, ODataUriParserConfiguration configuration, ExpandToken& expandTree, SelectToken& selectTree)\r\n   em Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select, String expand, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n   em Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\r\n   em System.Web.OData.Query.SelectExpandQueryOption.get_SelectExpandClause()\r\n   em System.Web.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)\r\n   em System.Web.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings)\r\n   em System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n   em System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n   em System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n   em System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext)\r\n   em System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
    }
}

}

响应JSON是这样的:

The response JSON is something like this:

    "@odata.context": "http://localhost:60275/odata4/$metadata#AnoValors",
"value": [
    {
        "1985": 13.822407187575308,
        "1986": 14.37878785150181,
        "1987": 14.914295678631518,
        "1988": 14.671386324309562,
        "ID": "IDDATA",            
    },...

以下查询均无效:

    http://localhost:60275/odata4/ControllerName(ID='IDData')/?$select=1985
    http://localhost:60275/odata4/ControllerName(ID='IDData')?$select=1985
    http://localhost:60275/odata4/ControllerName(ID='IDData')/?$select='1985'
    http://localhost:60275/odata4/ControllerName(ID='IDData')/?$select="1985"

我的模型课是:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;

    namespace OdataV4.Models{

    public class YearValue
    {      

        [Key]
        public string ID{ get; set; }
        public IDictionary<string, object> YEARVALUE { get; set; }

   }
  }

我正在使用:

    Entity Framework 6.1.3
    Microsoft.AspNet.OData 6.0.0
    Microsoft.AspNet.WebApi.OData 5.7.0
    Microsoft.AspNet.WebApi 5.0.0
    Microsoft.Data.OData 5.0.0
    Microsoft.OData.Core 7.0.0
    Microsoft.OData.Edm 7.0.0

有人知道这可能是什么吗?可以选择开放类型吗?

Does anyone knows what this could be? Are Open Types selectable?

推荐答案

感谢您回答我,说它应该可以工作,但看起来更难. 正如Sam Xu指出的那样,它可以与键"foo"一起使用,我在自己的字典上对其进行了测试,并且可以正常工作.这让我认为OData不会以数字为键,并且也不会.我通过在每年的数字前添加字母"a"解决了我的问题,并且知道它可以很好地进行选择.

Thank you for answering me, saying that it should work, it made look harder. As Sam Xu noted, it works with the key "foo", and I tested it on my dict and it worked. It made me think that OData doens't take a number as a key, and it doesn't. I solved my problem by appending the letter 'a' in front of each year number, and know it selects just fine.

这篇关于如何在OData打开数据类型上选择$ select?查询无效错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆