【发布时间】:2013-08-24 03:54:48
【问题描述】:
我有一个 .NET WebAPI 2 Odata 服务,我正在使用 Breeze 在它之上 OData服务基于VS2013 ASP.Net VNext版本 服务支持 展开 我设法欺骗 Microsoft OData 元数据序列化以提供具有外键的引用约束,如下所示:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="ODataGame.Models">
<EntityType Name="Incident">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Int32" Nullable="false"/>
<Property Name="Name" Type="Edm.String"/>
<Property Name="Desc" Type="Edm.String"/>
<NavigationProperty Name="DTask" Relationship="ODataGame.Models.ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTask" ToRole="DTask" FromRole="Incident"/>
</EntityType>
<EntityType Name="DTask">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Int32" Nullable="false"/>
<Property Name="Name" Type="Edm.String"/>
<Property Name="IncidentID" Type="Edm.Int32" Nullable="false"/>
<NavigationProperty Name="Incident" Relationship="ODataGame.Models.ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTask" ToRole="Incident" FromRole="DTask"/>
</EntityType>
<Association Name="ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTask">
<End Type="ODataGame.Models.Incident" Role="Incident" Multiplicity="0..1"/>
<End Type="ODataGame.Models.DTask" Role="DTask" Multiplicity="*"/>
<ReferentialConstraint>
<Principal Role="Incident">
<PropertyRef Name="ID"/>
</Principal>
<Dependent Role="DTask">
<PropertyRef Name="IncidentID"/>
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ODataGame_Models_DTask_Incident_ODataGame_Models_Incident_IncidentPartner">
<End Type="ODataGame.Models.Incident" Role="Incident" Multiplicity="0..1"/>
<End Type="ODataGame.Models.DTask" Role="DTask" Multiplicity="0..1"/>
</Association>
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Incident" EntityType="ODataGame.Models.Incident"/>
<EntitySet Name="DTask" EntityType="ODataGame.Models.DTask"/>
<AssociationSet Name="ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTaskSet" Association="ODataGame.Models.ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTask">
<End Role="Incident" EntitySet="Incident"/>
<End Role="DTask" EntitySet="DTask"/>
</AssociationSet>
<AssociationSet Name="ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTaskSet" Association="ODataGame.Models.ODataGame_Models_DTask_DTaskPartner_ODataGame_Models_Incident_DTask">
<End Role="DTask" EntitySet="DTask"/>
<End Role="Incident" EntitySet="Incident"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
问题是 Web API odata 在一个额外的结果元素中返回扩展结果,而不是像这样直接作为 jason 数组:
"__metadata":{
"id":"http://localhost:27698/odata/Incident(3)","uri":"http://localhost:27698/odata/Incident(3)","type":"ODataGame.Models.Incident"
},"DTask":{
"results":[
{
"__metadata":{
"id":"http://localhost:27698/odata/DTask(1)","uri":"http://localhost:27698/odata/DTask(1)","type":"ODataGame.Models.DTask"
},"Incident":{
"__deferred":{
"uri":"http://localhost:27698/odata/DTask(MEIR%20MISSING)/Incident"
}
},"ID":1,"Name":"kk","IncidentID":3
}
]
},"ID":3,"Name":"asas","Desc":"zz"
}
有没有办法配置微风来正确处理?
如果我仅在一个元素中具有导航属性而另一侧没有反向属性,例如在我的情况下,事件包含任务集合但任务不需要引用事件,Breeze 不需要似乎支持正确,有没有办法配置它?
【问题讨论】:
-
您是否解决了有关微风未处理的额外结果元素的问题?我在这里遇到同样的问题:stackoverflow.com/questions/19060244/…
-
您能分享一下您是如何欺骗 OData EDM 序列化程序以包含引用约束的吗?由于缺少约束,我很难识别 1 到 m 的关联。
标签: odata breeze asp.net-web-api