不会在元数据中创建Breeze导航属性

时间:2014-03-09 00:20:17

标签: javascript odata breeze xpo

我正在尝试将breeze.js与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")

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

1 个答案:

答案 0 :(得分:1)

我通过调试breeze.js库找到了问题。 Breezejs默默地!如果没有定义约束,则忽略导航属性。我认为至少应该向javascript控制台打印警告。我会提出一个关于它的推送请求。 breeze.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未定义,因此方法会静默返回并忽略导航属性。 我认为这个行为也应该在breeze.js文档中定义。