我想從數據庫中加載一個實體,然後利用它的ICollection(從模型類)加載某些子數據。這將是非常簡單,從個人視圖模型做的,如果它是一個1對多的關係,但我有一點更復雜的結構 -當添加額外的擴展複雜類型到微風實體
父母有許多兒童。每個孩子都有很多孫子,需要與適當的孩子聯繫起來。層次結構需要保持機智。
,我拿出迄今可能不是最好的辦法中的其他選項,所以我我的問題是 - 什麼是加載了孫子的最佳實踐 - 或者一些其他的方法?
在構造函數中在配置metadataStore -
function configureMetadataStore(metadataStore) {
metadataStore.registerEntityTypeCtor(
'Child', null, childInitializer);
}
function childInitializer(child) {
child.grandchildren = (Do something here)
return grandchildren;
});
}
在視圖模型,孩子們正在填充 -
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;
};
或其他方法?
謝謝,他們不是單向的。你介意我更新了我的問題得到一些額外的方向,或者你想爲我慶祝這個作爲答案,並專門開闢了一個新問題有關查詢? – 2013-04-24 18:54:59
沒問題。具體關於查詢的新問題可能會更好。 – 2013-04-24 18:58:36
感謝已經這樣做了,如果你有機會看看http://stackoverflow.com/questions/16200400/how-when-to-query-extended-entities-in-breeze – 2013-04-24 19:18:26