我的 EDM 中有两个实体,Application
and Address
几乎类似于以下内容:
class Application
{
ICollection<Address> Addresses { get; set; }
}
class Address { }
在客户端上,我创建每个实例并尝试添加address
实例到Application.addresses
收藏:
var address = addressType.createEntity(...);
var application = applicationType.createEntity(...);
application.addresses.push(address);
不幸的是,我收到运行时异常:“Unable to get value of the property 'name': object is null or undefined
".
我跟踪异常回到checkForDups
函数于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
is undefined
所以尝试访问时出现错误name
财产。
添加一个简单的检查可以解决问题,并允许添加到集合中:
if (!inverseProp) {
return true;
}
所以,归根结底,问题是:这是一个错误还是只是 Breeze 不支持一对多单向?