breezejs:已创建导航属性,但未填充数据 [英] breezejs: navigation property is created but not filled with data

查看:46
本文介绍了breezejs:已创建导航属性,但未填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导航属性还有另一个问题,但是这次我的配置是WCF数据服务+ EF。

I'm having yet another issues with navigation properties but this time my configuration is WCF Data Service + EF.

基本上元数据看起来不错,我有参考约束,关联等...我已经在模型中设置了[ForeignKey]属性。

Basically the metadata looks good, I have the referential constraints, association, etc... I've set the [ForeignKey] attribute in the model.

导航属性是在客户端创建的,但是当数据(使用$ expand)检索,尽管服务器肯定会返回数据,但不会填充该集合:

The navigation property is created on the client-side, but when data is retrieved (using $expand), the collection is not filled although data is definitely returned by the server :

此处的关联在OpenPosition上的missions_id和任务上的id之间。

The association here is between mandate_id on OpenPosition and id on Mandate.

我注意到OpenPositions集合中的Mandate实体包含uri递延给____。我没有在WebApi上看到它,所以也许是问题所在,或者只是正常现象。

I've noticed that the Mandate entity in the OpenPositions collection contains __deferred with the uri to the entity. I had not seen that with WebApi so maybe that's the problem, or maybe it's just normal behaviour.

我是否缺少某些东西?

Is there something I'm missing ?

编辑

客户端查询是:

  var query = breeze.EntityQuery.from("Mandates").inlineCount().expand("OpenPositions");
  return manager.executeQuery(query.using(service)).then(function (result) {
        logger.info(result);
    }).fail(function (error) {
        logger.error(error);
    });

编辑2

导航属性未填充的原因是,对于WCF Dataservice,导航属性作为一个对象返回,该对象包含一个称为结果的Array属性。

The reason the navigation property is not filled is because in the case of WCF Dataservice, the navigation property is returned as an object, which contains an Array property called results.

对于WebAPI,导航属性以数组形式返回。

Whereas in the case of WebAPI, the navigation property is returned as an Array.

请注意,在两种情况下,都使用相同的数据模型(EF上下文)。

Note that in both cases, the same data model (EF context) was used.

查看屏幕截图:

WCF:

WebAPI:

但是微风需要一个Array,否则它会忽略导航属性并返回null:

But breeze expects an Array otherwise, it just ignores the navigation property and returns null:

   // needed if what is returned is not an array and we expect one - this happens with __deferred in OData.
        if (!Array.isArray(relatedRawEntities)) return null;


推荐答案

好的,终于可以了:)我现在正在使用breezejs在github上的最新提交,这解决了我的问题。我认为,直到现在,通过WCF进行的微风都无法与ODATA2一起使用。 ODATA规范对此很清楚:

Ok, FINALLY it's working :) I am now using the latest commit of breezejs on github and this fixed my problem. In my opinion breeze via WCF never worked until now with ODATA2. The ODATA specification is clear about that:


  • ODATA V1:集合表示为数组

  • ODATA V2:集合表示为包含数组的对象。

在使用github版本之前,我可以使其工作的唯一方法通过在datajs中将MAX_DATA_SERVICE_VERSION指定为1.0来实现。

The only way I could get it to work before using the github version of breezejs, was by specifying MAX_DATA_SERVICE_VERSION to 1.0 in datajs.

无论如何,现在都很好。我等不及轻轻松松的发布了:)顺便说一下,我可能会放弃NHibernate的OpenAccess。 NH WebAPI控制器是否与EF WebAPI控制器一样完整?

Anyway, that's all good now. I can't wait for the breeze release :) By the way it's likely I'm going to ditch OpenAccess for NHibernate. Is the NH WebAPI controller as complete as the EF WebAPI controller ?

这篇关于breezejs:已创建导航属性,但未填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆