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.