没有逆属性填充子实体 [英] Child entities not populated without inverse property

查看:73
本文介绍了没有逆属性填充子实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有单向1-> n导航的数据结构(没有n-> 1),但是不幸的是,API不在我的控制之下。问题是,当我从服务中获取数据时,子级未添加到父级(尽管我确实从服务器接收了建筑物,但建筑物集合仍然为空)。元数据是手动构建的。

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.

我试图找出问题所在,发现大概是12635行:

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:


省略导航属性

有时您想忽略
关联的一侧的导航属性。例如,您可能拥有Person.Gender,但您并没有
想要Gender.Persons;没有充分的理由从
男性性别实体导航到所有男性人物,也没有理由招致为该导航更新可观察数组的
开销。
幸运的是,您可以在关联的原则
侧省略导航属性。性别是本例中的主体
,因此您可以省略Gender.Persons。

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.

以下是定义:

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);
    }

关于如何解决此问题而不增加反属性的任何想法?否则,一切都会正常工作,因为Edmunds示例与我所做的完全一样,不同之处在于它具有逆属性。

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.

推荐答案

编辑自v Breeze 1.3.5(现已提供)(2013年6月4日)开始,此问题已修复。

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...

我们还有其他一些要解决的问题首先(NHibernate和Mongo的示例),但是现在这是头等大事。

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.

注意,此错误仅在单向1-> n时发生。 Breeze的单向n-> 1(在大多数模型中更常见的情况)没有问题。

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).

这篇关于没有逆属性填充子实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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