本文介绍了在查询OData的嵌套字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的类,它是通过GET调用公开为OData的服务

I have the below class which is exposed as oData service through a GET call

class Book
{
    public string Id {get; set;}
    public string Name {get; set;}
    public Dynamicproperties Dictionary<string,object> {get; set;}
}

假设书的对象包含以下数据

Assume an object of Book contains below data

new Book
{
   Id="1",
   Name = "oData",
   new Dictioanry<string,object>
   {
       { "chapter1", 
         new Dictionary<string,object>
         {
           "page1",
            new Dictionary<string,object>
            {
                "topic", "introduction"  
            }
         }
      }
   }
}

我能理解用户可以像查询书的性质的 的,并支持
此查询我需要为我的BooksController中内这些属性干将。但是,用户如何查询嵌套的字典里面的属性。假设如果用户想要知道的值
第一章第1页的话题,用户如何查询呢?。我应该怎么做,以支持该查询?我无法弄清楚。我想AP preciate任何帮助。

I could understand user can query properties of Book like http://localhost:1234/Books('1')/Name and to support this query i need to have getters for those properties inside my BooksController. But how can a user query the properties inside the nested dictionary. Suppose if the user wants to know value of topic of page1 of chapter1, how can a user query it ?. What should I do to support that query ?. I am not able to figure it out. I would appreciate any help.

推荐答案

我觉得嵌套的字典中没有的Web API的OData现在支持。事实上,

I think nested dictionary is not supported now in Web API OData. Actually,

公众解释Dynamicproperties {搞定;设置;}

是保持动态特性的容器。目前,动态属性可以是在OData的定义的结构性质中的一个。

is a container to hold the dynamic properties. Currently, the dynamic properties can be one of structural properties defined in OData.

作为的OData规范说:

4.3结构特性

一个结构属性是具有以下类型之一(结构类型)的属性

A structural property is a property (of a structural type) that has one of the following types:

·原始类型

·复杂类型

·枚举类型

·上面的一个集合

希望它可以提供帮助。谢谢你。

Hope it can help. Thanks.

这篇关于在查询OData的嵌套字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 20:08