在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>
,效果很好。
答案 0 :(得分:1)
OData中的Dictionary支持是Open Type,_map称为动态属性,它不会在元数据中显示,你应该在元数据中使用属性:
<EntityType Name="Employee" OpenType="true">