2013-08-21 43 views
1

我有一個.NET的WebAPI 2 OData服務,我有微風在它的頂部 工作的OData服務是基於VS2013 ASP.Net VNext版本 該服務支持擴大 我管理欺騙微軟的OData元數據序列化提供參照約束與外鍵,像這樣:微風使用Web API的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> 

的問題是,網絡API的OData收益擴大的結果額外的結果元素中,並不能直接作爲賈森陣列狀所以:

 "__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來正確處理?

如果我有一個導航屬性只在一個元素沒有另一邊的反向屬性,例如在我的情況下事件持有任務的集合,但不需要事件的引用任務,Breeze做似乎沒有正確支持,有沒有一種方法來配置?

+0

您是否解決了關於未被微風處理的額外結果元素的問題?我在這裏有同樣的問題:http://stackoverflow.com/questions/19060244/breezejs-navigation-property-is-created-but-not-filled-with-data – Sam

+0

你能分享你如何欺騙OData電火花序列化器包含ReferentialConstraint?由於缺少約束條件,我無法輕易識別1-m關聯。 – khaledh

回答

0

我並不熟悉的微風的OData適配器,當你指的是「ASP.Net VNext版」你在這裏所說的不穩定,未發行的技術。你正在努力尋找最前沿。

如果您喜歡它,歡迎您進入Breeze OData「dataserviceAdapter」(未記錄,但in GitHub)和「jsonResultsAdapter」。對於後者,您應該能夠將服務器發送給客戶端的任何東西彎曲(如果您不能,我想知道它)。

+0

我能夠改變微風正確處理結果屬性,第二個問題是更通用的微風,微風處理一個用例,其中只有一個實體,但沒有其他導航屬性,例如,如果我有以及事件的集合我想要事件有一個任務數組,但我不想有事件的任務財產。 –

+0

是的,您可以在關聯的一側有一個導航屬性,但不在另一側。 – Ward

0

從版本1.4.4開始,Breeze支持OData v3。這可能是您遇到的問題。

此前只支持OData v2。