在Odata服务中,无法为Dictionary属性生成元数据
本文关键字:属性 Dictionary 元数据 服务 Odata | 更新日期: 2023-09-27 18:07:13
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; };
}
在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>
它工作得很好
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