在Odata Service中无法为Dictionary属性生成元数据

时间:2015-08-10 12:28:52

标签: c# dictionary odata

在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; };
    }

在WebApiConfig.cs

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

生成的元数据是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>

此处属性遗失public Dictionary<string, object> _map why so? any clue? but if i use property like ``public Dictionary<string, string>,效果很好。

1 个答案:

答案 0 :(得分:1)

OData中的Dictionary支持是Open Type,_map称为动态属性,它不会在元数据中显示,你应该在元数据中使用属性:

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

仅供参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4