0
votes

I found a bug concerning the ComplexType properties. I have an Object which has a property which is a collection of other objects which I defined in the client-side metadata as a Complex property, i.e. "isComplexType: true". However all properties of a complex type are set to 'undefined'. I did a bit of debugging and found this:

// target and source may not be entities that can also be complexTypes.
function updatePropertyFromRawEntity(dp, target, rawSource) {
    var val = getPropertyFromRawEntity(rawSource, dp);
    if (val === undefined) return;
    if (dp.isComplexProperty) {
        var coVal = target.getProperty(dp.name);
        dp.dataType.dataProperties.forEach(function (cdp) {
            // recursive call
            updatePropertyFromRawEntity(cdp, coVal, val);
        });
    } else {
        target.setProperty(dp.name, val);
    }
}

The rawSource parameter is an array(in case of complexTypes) is an array of objects. So the problem is when invoking the getPropertyFromRawEntity(), it passes an array not an object:

function getPropertyFromRawEntity(rawEntity, dp) {
    var propName = dp.nameOnServer || dp.isUnmapped && dp.name;
    return parseValueForDp(rawEntity[propName], dp);
}

So rawEntity[propName] will always be undefined because its an array.

1

1 Answers

0
votes

A Breeze ComplexType has a well defined structure specified by metadata. Any property, (except) the key can have its datatype be a complexType. However, what you want, I think, is an "untyped" structure. This can be accomplished by defining the property as having a data type of "Undefined", something like:

  var newProp = new DataProperty({
                name: "Foo"
                dataType: DataType.Undefined,
                isNullable: true,
                isUnmapped: true
            });
  entityType.addProperty(newProp);

The "Undefined" dataType will accept data of any type and structure.