Breeze.js:将元素添加到导航属性集合中而没有反向相关会引发异常[无法获取属性'name'的值] [英] Breeze.js: adding an element to a navigation property collection without inverse rel raises an exception [Unable to get value of the property 'name']

查看:74
本文介绍了Breeze.js:将元素添加到导航属性集合中而没有反向相关会引发异常[无法获取属性'name'的值]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的EDM中有两个实体,分别是 Application Address ,如下所示:

I have two entities in my EDM, Application and Address pretty much like the following:

class Application
{
    ICollection<Address> Addresses { get; set; }
}

class Address { }

在客户端上,我为每个实例创建一个实例,并尝试将 address 实例添加到 Application.addresses 集合中:

On the client, I create an instance of each and try to add the address instance to the Application.addresses collection:

var address = addressType.createEntity(...);
var application = applicationType.createEntity(...);

application.addresses.push(address);

不幸的是,我收到一个运行时异常消息: 无法获得属性名称:对象为null或未定义

Unfortunately, I get a runtime exception saying: "Unable to get value of the property 'name': object is null or undefined".

我将异常追溯到 checkForDups 函数中的 breeze.debug.js@9393-9404 (v1.2.8):

I tracked the exception back to the checkForDups function in breeze.debug.js@9393-9404 (v1.2.8):

function checkForDups(relationArray, adds) {
    // don't allow dups in this array. - also prevents recursion 
    var inverseProp = relationArray.navigationProperty.inverse;
    var goodAdds = adds.filter(function(a) {
        if (relationArray._addsInProcess.indexOf(a) >= 0) {
            return false;
        }
        var inverseValue = a.getProperty(inverseProp.name);
        return inverseValue != relationArray.parentEntity;
    });
    return goodAdds;
}

发生这种情况时,我的实体处于一对多的单向关系(没有反向导航属性);由于在运行时 relationArray.navigationProperty.inverse undefined 的结果,因此尝试访问<$ c时出现错误$ c>名称属性。

As it happens, my entities are in a one-to-many unidirectional relationship (without an inverse navigation property); as a result at runtime relationArray.navigationProperty.inverse is undefined and so the error when trying to access the name property.

添加简单的检查即可解决此问题,并允许将其添加到集合中:

Adding a simple check fixes the problem, and allows adding to the collection:

if (!inverseProp) {
    return true;
}

毕竟,问题是:这是bug还是仅仅是从Breeze 1.3开始,

So after all this the question is: is this a bug or is it simply that Breeze does not support one-to-many unidirectional?

推荐答案

编辑表示Breeze不支持一对多单向? .5,现已发布(2013年6月4日),此问题已修复。

Edit As of v Breeze 1.3.5, available now (June 4 2013), this has been fixed.

编辑:好的,这是一个错误,但是我无法获得当前版本的修复程序。我将尝试在以下版本中获得它。

Ok, this IS a bug, but I couldn't get the fix in for this current release. I will try to get it in the following release.

您建议的修复程序是一个好主意,实际上只是掩盖了问题所在。

The fix that you suggested, which was a good idea, actually only hides the issue.

真正的问题是,对于我们在1-> n方向(即不在n->方向)进行单向导航的情况,微风没有足够的元数据1个方向)。因此,导航集合中的重复实体检查将不起作用,并且也将丢失自动将孩子挂接到父母的功能。

The real problem is that breeze does not have sufficient metadata for the case where we have a unidirectional navigation in the 1->n direction (i.e. not in the n->1 direction). Because of this, duplicate entity checking in the navigation collection will not work and automatic hookup of children to parents will be missing as well.

在获得解决方案之前,最简单的解决方法是简单地使其成为双向导航。请注意,在另一个方向上进行单向导航也可以。

The simplest work around until we get the fix in is to simply make it a bidirectional navigation. Note that unidirectional navigation in the other direction works just fine.

这可能是一个错误

OrderDetails和Products之间的单向导航的DocCode示例项目中的示例。但是在那种情况下,我们允许从OrderDetail-> Product(1-1)导航,而不是从Product-> OrderDetails(1-n)导航。

We do have an example in our DocCode sample project of a unidirectional navigation between OrderDetails and Products. But in that case we allow navigation from a OrderDetail -> Product (1-1) but not from Product -> OrderDetails (1-n).

您的情况似乎相反,即允许1-n但不允许相应的1-1。我将创建一些测试,如果可以对其进行复制,它将在下一版本中修复。

Your case appears to be the opposite, i.e. allowing 1-n but disallowing the corresponding 1-1. I will create some tests and if I can repro this, it will be fixed in the next release.

发生这种情况时,我会在此发布。 (以及查找它的方法:)

I will post back here when that occurs. ( and thx for finding it :)

这篇关于Breeze.js:将元素添加到导航属性集合中而没有反向相关会引发异常[无法获取属性'name'的值]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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