2

I have a data structure with unidirectional 1->n navigation (no n->1) but unfortunately the API is not under my control. The problem is that when I get the data from the service the children are not added to the parent (the building collection remains empty although I do receive buildings from the server). The metadata is constructed manually.

I tried to track down the problem and I found that it's probably line 12635:

if (!inverseProperty) return;

If there is no reverse property it does not push the found related entity into the observable array. This is very odd because the breeze documentation explicitly states that:

Omitting navigation properties

Sometimes you want to omit a navigation property one side of an association. For example, you may have Person.Gender but you don't want Gender.Persons; there is no good reason to navigate from the "Male" gender entity to all male Persons and no reason to incur the overhead of updating an observable array for that navigation. Fortunately, you can omit the navigation property on the principle side of the association. The Gender is the principal in this example so you can omit Gender.Persons.

Here are the definitions:

function addBuildingType(store) {
        store.addEntityType({
            shortName: 'Building',
            namespace: 'Helios',
            autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
            dataProperties: {
                id: { dataType: DataType.Int32, isNullable: false, isPartOfKey: true },
                address: { dataType: DataType.String },
                city: { dataType: DataType.String },
                client: { dataType: DataType.String },
                contractNo: { dataType: DataType.Int32 },
                includedDevices: { dataType: DataType.Int32 },
                phoneNo: { dataType: DataType.String },
                totalDevices: { dataType: DataType.Int32 },
                zipCode: { dataType: DataType.String }
            }
        });
    } 

    function addScheduledEventType(store) {
        store.addEntityType({
            shortName: 'ScheduledEvent',
            namespace: 'Helios',
            autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
            dataProperties: {
                id: { dataType: DataType.Int32, isNullable: false, isPartOfKey: true },
                startTime: { dataType: DataType.DateTime, isNullable: false },
                duration: { dataType: DataType.DateTimeOffset, isNullable: false }
            },
            navigationProperties: {
                buildings: { entityTypeName: "Building:#Helios", isScalar: false, associationName: "ScheduledEvent_Buildings" }
            }
        });

        store.registerEntityTypeCtor(
            'ScheduledEvent', null, scheduledEventInitializer);
    }

Any ideas on how to work around this without adding the inverse properties? Otherwise everything should work because the Edmunds sample does exactly what I do with the difference being that it has an inverse property.

Undo
  • 25,519
  • 37
  • 106
  • 129
  • If updating to the latest Breeze solved your issue, I'm wondering if you had to change anything in your entity definitions... specifically how does Breeze know which set of Building entities are related to a particular ScheduledEvent entity. – Adam Jul 26 '13 at 21:37

1 Answers1

2

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


This is known bug and we will try to get a fix out for it soon...

We have a few other things we are trying to get out first (samples for NHibernate and Mongo), but this is now a top priority bug.

Note, this bug only occurs with unidirectional 1 -> n. Breeze has no problem with a unidirectional n -> 1 ( a more common occurence in most models).

Jay Traband
  • 17,053
  • 1
  • 23
  • 44
  • I am using 1.4.8 Breeze version with "nodb" conception. I am trying to configure model to have a list of key/value pairs. I see that correct data were transferred, but Breeze does not populating that array. Non scalar variable with that type working fine, but not arrays. – Ivan Sokalskiy Apr 14 '14 at 22:20
  • 1
    Could you post this as a separate question along with your metadata that describes the type with a nonscalar property definition? – Jay Traband Apr 14 '14 at 23:51
  • Thank you for blazing fast reaction! I just created separate question about my case: http://stackoverflow.com/questions/23093832/non-scalar-navigation-properties-are-not-populating-with-nodb-conception – Ivan Sokalskiy Apr 15 '14 at 20:27