Neo
Neo

Reputation: 16219

In Odata Service unable to generate metadata for Dictionary property

In Employee.cs

 public class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string test { get; set; }
        public Dictionary<string, object> _map { get; set; };
    }

In WebApiConfig.cs

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Employee>("Employees");
            config.MapODataServiceRoute(
            routeName: "ODataRoute",
            routePrefix: "odata",
            model: builder.GetEdmModel());

Generated metadata is http://localhost:52038/odata/$metadata

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="MyService.Models">
    <EntityType Name="Employee">
    <Key>
    <PropertyRef Name="Id"/>
    </Key>
    <Property Name="Id" Type="Edm.Int32" Nullable="false"/>
    <Property Name="Name" Type="Edm.String"/>
    <Property Name="test" Type="Edm.String"/>
    </EntityType>
    </Schema>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
    <EntityContainer Name="Container">
    <EntitySet Name="Employees" EntityType="MyService.Models.Employee"/>
    </EntityContainer>
    </Schema>
    </edmx:DataServices>
    </edmx:Edmx>

here property is missing public Dictionary<string, object> _map why so? any clue? but if i use property like ``public Dictionary<string, string> it works great.

Upvotes: 0

Views: 590

Answers (1)

Fan Ouyang
Fan Ouyang

Reputation: 2132

The Dictionary support in OData is Open Type, _map there called dynamic properties, it won't show in metadata, you should the attribute in metadata:

<EntityType Name="Employee" OpenType="true">

FYI : http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4

Upvotes: 1

Related Questions