Search code examples
c#asp.net-web-apiodata

Querying a nested dictionary in 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"  
            }
         }
      }
   }
}

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.


Solution

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

    public Dictionary Dynamicproperties {get; set;}

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

    As OData spec says:

    4.3 Structural Properties

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

    · Primitive type

    · Complex type

    · Enumeration type

    · A collection of one of the above

    Hope it can help. Thanks.