I want to load an entity from the database, and then using it's ICollection (from the model class) load up some child data. This would be simple enough to do from individual view models if it was a 1 to many relationship, but I have a bit more complex structure -
Parent has many children. Each child has many grandchildren, that need to be linked back to the proper child. The hierarchy needs to remain in tact.
The other options that I have come up with so far may not be the best way so I my question is - what is the best practice to load up the grandchildren - or some other method?
in a constructor while configuring the metadataStore -
function configureMetadataStore(metadataStore) {
metadataStore.registerEntityTypeCtor(
'Child', null, childInitializer);
}
function childInitializer(child) {
child.grandchildren = (Do something here)
return grandchildren;
});
}
In the viewmodel where children are being populated -
function refresh() {
return datacontext.getChildren(childs, parentId);
}
var addGrandChildren = function () {
$.each(childs, function (i) {
var grandChildren = ko.observableArray();
var childId = $(this).data(id);
datacontext.getGrandChildren(grandChildren, childId);
});
return;
};
Or some other method?