如何/何时在Breeze中查询“扩展"实体 [英] How/when to query 'extended' entities in Breeze

查看:104
本文介绍了如何/何时在Breeze中查询“扩展"实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewModel可以加载子代"实体,并且我还想根据加载的每个子代显示孙代"实体.为简化起见,我需要帮助确定如何查询这些对象并在浏览器中的适当树"下显示它们(为我对编码语言的but惜表示歉意)

I have a ViewModel that loads up 'child' entities and I want to also display 'grandchild' entities based off of each child that is loaded. To simplify things, I need help identifying how to query these objects and display them under the proper 'tree' in the browser (apologies for my butchering of coding language : ))

我正在使用Knockout绑定数据并使用Breeze加载实体.此问题是何时添加扩展名的扩展Breeze实体上添加其他复杂类型

I am using Knockout to bind the data and loading up the entities with Breeze. This question is an extension of When to add extend additional complex types onto a Breeze entity

而且-我的模型首先是EF代码,我有一个配置定义了子孙之间的一对多关系,我认为 Breeze已经知道了,但是我想弄清楚如何利用这一点.

Also - my model is EF code first and I have a configuration defining a one to many relationship between children and grandchildren, and I think Breeze knows this already but I am trying to figure out how to take advantage of this.

childs.js(视图模型)

childs.js (view model)

var childs = ko.observableArray();
var grandChilds = ko.observableArray();
var parentId = ko.observable();

function refresh() {
    var parentId = (parent).parentId;  // << for ex. don't worry about this line : )
    return Q.all([getChildren(), getGrandChildren()]);
}

function getChildren() {
    return datacontext.getChildren(childs, parentId);
}

function getGrandChildren() {
    return datacontext.getGrandChildren(grandChilds);
}

和视图(childs.html)

and in the view (childs.html)

<div data-bind="foreach: childs">
    <div title="Go to Child Details">
        <div><strong data-bind="text: name"></strong></div>
        <div><strong data-bind="text: gender().description"></strong></div>
    </div>
    <div>
        <!-- ko.compose { view: grandChilds} --><!--/ko-->
    </div>
</div>

以及我当前的数据上下文以供参考

And my current datacontext for reference

    var getChilds= function (childsObservable, parentId) {

        var query = EntityQuery.from('Childs')
            .where('parentId', '==', parentId)
            .expand('grandChildren')
            .orderBy('id');

        return manager.executeQuery(query)
            .then(querySucceeded)
            .fail(queryFailed);

        function querySucceeded(data) {
            if (childsObservable) {
                childsObservable(data.results);
            }
            logger.log('Retrieved [Childs] and [Grandchilds] from remote data source', data, system.getModuleId(datacontext), true);
        }
    };

我只想加载子孙中的子孙,并且由于有很多子,我只想在正确的子项下显示孙子,而不是在一个列表中显示所有子孙.任何帮助将不胜感激.

I want to load up only grandchildren of the children, and since there are many children I want to only display grandchildren under the correct child, not all grandchildren in one list. Any help would be appreciated.

推荐答案

您拥有三种查询和链接"相关实体的基本方法.

You have three basic approaches to querying and "linking" related entities.

1)使用 EntityQuery.expand

2)使用 EntityAspect.loadNavigationProperty

3)创建一个恰好包含整个图形的广泛" EntityQuery,并且所有父/子关系都将自动链接.

3) Create a "broad" EntityQuery that just happens to encompass the entire graph and all of the parent/child relations will be automatically linked.

这篇关于如何/何时在Breeze中查询“扩展"实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆