breeze 得到 collection 个实体而不是 objects

breeze get a collection of entities not objects

使用 restful node.js 服务器并发送包裹在一个实体中的 collection 个实体 object (查找)一切正常,但是 collection 中的实体被 breeze 视为普通的 object 而不是实体。有没有办法解决这个问题,也可以使用复杂的 object 而不是使用实体进行查找,因为它仅用作持有人,仅此而已。感谢帮助

服务器的响应是这种格式

[
  oranges:[{id:1, name:'juicy'}, {id:2, name:'no seeds'}],
  apples:[{id:1, name:'red'}, {id:2, name:'green'}]
]

使用此查询:

breeze.EntityQuery.from('users/lookups')
            .using(this.manager).execute()
            .then(this.querySucceeded)
            .catch(this.queryFailed);

这是查找的元数据代码

var entityType = {
   name: this.entityNames.Lookup,
   defaultResourceName: 'users/lookups',
   autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
   dataProperties: {
      lookupID: {dataType: DT.Int32, isPartOfKey: true}
   },
   navigationProperties:  {
      apples: {
             entityTypeName: this.entityNames.Apple
       },
      orange: {
             entityTypeName: this.entityNames.Orange
       }
   }
};

Orange 和 Apple 的元数据

var entityType = {
    name: this.entityNames.Apple,
    defaultResourceName: 'users/lookups/Apples',
    dataProperties: {
         id: {type: DT.Int32},
         image: {type: DT.String},
         name: { complexTypeName: 'Translation:#model', isNullable: false}
    }
 };


var entityType = {
    name: this.entityNames.Orange,
    defaultResourceName: 'users/lookups/Oranges',
    dataProperties: {
         id: {type: DT.Int32},
         image: {type: DT.String},
         name: { complexTypeName: 'Translation:#model', isNullable: false}
    }
 };

复杂类型翻译的元数据

var entityType = {
    name: 'Translation',
    isComplexType: true,
    dataProperties: {
         fr: {type: DT.String},
         en: {type: DT.String}
    }
 };

您的服务器对苹果和橙子的响应应具有响应数据中标识的类型。这样他们就可以被识别为实体:

[
  oranges:[
    {$type:model.Orange, id:1, name:'juicy'}, 
    {$type:model.Orange, id:2, name:'no seeds'}
  ],
  apples:[
    {$type:model.Apple, id:1, name:'red'}, 
    {$type:model.Apple, id:2, name:'green'}
  ]
]

你可以看到更多关于lookups in the Breeze documentation