1

我正在尝试与 OData 服务器(基于 XPO)进行交流。在来自服务器导航属性的元数据 xml 中存在,但它们不是为客户端类型的元数据创建的。我做错了什么还是有错误?

服务器元数据 xml:

http://odataserver/Db.svc/$metadata

    <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="Namespace">
<EntityType Name="Question">
<Key>
<PropertyRef Name="Oid"/>
</Key>
<Property Name="Oid" Type="Edm.Int32" Nullable="false"/>
<Property Name="No" Type="Edm.String"/>
<Property Name="Header" Type="Edm.String"/>
<NavigationProperty Name="Chapter" Relationship="Namespace.Question_Chapter_Chapter_Questions" ToRole="Chapter_Questions" FromRole="Question_Chapter"/>
</EntityType>
<EntityType Name="Chapter">
<Key>
<PropertyRef Name="Oid"/>
</Key>
<Property Name="Oid" Type="Edm.Int32" Nullable="false"/>
<Property Name="No" Type="Edm.String"/>
<Property Name="Name" Type="Edm.String"/>
<NavigationProperty Name="Questions" Relationship="Namespace.Question_Chapter_Chapter_Questions" ToRole="Question_Chapter" FromRole="Chapter_Questions"/>
</EntityType>
<Association Name="Question_Chapter_Chapter_Questions">
<End Type="Namespace.Chapter" Role="Chapter_Questions" Multiplicity="0..1"/>
<End Type="Namespace.Question" Role="Question_Chapter" Multiplicity="*"/>
</Association>
<EntityContainer Name="DbService" m:IsDefaultEntityContainer="true">
<EntitySet Name="Question" EntityType="Namespace.Question"/>
<EntitySet Name="Chapter" EntityType="Namespace.Chapter"/>
<AssociationSet Name="Question_Chapter_Chapter" Association="Namespace.Question_Chapter_Chapter_Questions">
<End Role="Question_Chapter" EntitySet="Question"/>
<End Role="Chapter_Questions" EntitySet="Chapter"/>
</AssociationSet>
</EntityContainer>
<Annotations Target="Namespace.Chapter/No">
<ValueAnnotation Term="Org.OData.Validation.V1.Size" Int="100"/>
</Annotations>
<Annotations Target="Namespace.Chapter/Name">
<ValueAnnotation Term="Org.OData.Validation.V1.Size" Int="100"/>
</Annotations>
<Annotations Target="Namespace.Question/No">
<ValueAnnotation Term="Org.OData.Validation.V1.Size" Int="100"/>
</Annotations>
<Annotations Target="Namespace.Question/Header">
<ValueAnnotation Term="Org.OData.Validation.V1.Size" Int="100"/>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

问题有一个导航属性:

<NavigationProperty Name="Chapter" Relationship="Namespace.Question_Chapter_Chapter_Questions" ToRole="Chapter_Questions" FromRole="Question_Chapter"/>

但是当我发出命令时:

manager.metadataStore.getEntityType("Question")

将元数据加载到微风后,结果在 navigationProperties 数组中有 0 项。

4

1 回答 1

1

我通过调试breeze.js 库发现了问题。Breezejs 默默无闻!如果没有定义约束,则忽略导航属性。我认为它至少应该将有关它的警告打印到 javascript 控制台。我将对此提出推送请求。微风.debug.js 中的问题行如下。

  function parseCsdlNavProperty(entityType, csdlProperty, schema) {

   ...

    var constraint = association.referentialConstraint;
    if (!constraint) {
        // TODO: Revisit this later - right now we just ignore many-many and assocs with missing constraints.
        return;
        // Think about adding this back later.
        //if (association.end[0].multiplicity == "*" && association.end[1].multiplicity == "*") {
        //    // many to many relation
        //    ???
        //} else {
        //    throw new Error("Foreign Key Associations must be turned on for this model");
        //}
    }

 ...
}

由于constraint未定义,方法静默返回并忽略导航属性。我认为这种行为也应该在微风.js 文档中定义。

于 2014-03-11T00:31:56.467 回答