本文介绍了微风的Web API的OData工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET的WebAPI 2的OData服务,我与微风在它上面工作
所述的OData服务是基于VS2013 ASP.Net VNext版本
该服务支持扩大
我设法欺骗微软的OData元数据序列化提供参照约束,象这样的外键:

I have a .NET WebAPI 2 Odata service and i am working with Breeze on top of itThe OData service is based on the VS2013 ASP.Net VNext versionThe service supports expandI managed to trick the Microsoft OData metadata serialize to provide the referential constraint with the foreign key like so:

<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返回展开结果的额外结果元件内,而不是直接作为杰森阵列像这样:

The problem is that the web API odata returns expand result within an extra result element and not directly as a jason array like so:

     "__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"
          }

有没有配置微风的正确处理办法?

is there a way to configure breeze to handle that correctly?

如果我有没有在另一侧的反向属性只有内一种元素的导航属性,例如在我的情况下的事件保持任务的集合,但一个任务不需要具有对入射的参考,微风不似乎是正确的支持,有没有配置的一种方式?

If i have a navigation property only within one element without a reverse property on the other side, for example in my case an incident holding a collection of task but a task not needing to have a reference to the incident, Breeze does not seems to support that correctly, is there a way to configure that?

推荐答案

由于1.4.4版本现已推出,微风支持的OData V3。这很可能你遇到的问题。

As of version 1.4.4, available now, Breeze supports OData v3. This was likely the issue you were experiencing.

previously唯一的OData v2进行了支持。

Previously only OData v2 was supported.

这篇关于微风的Web API的OData工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:29