breezejs:向实体类型添加引用约束 [英] breezejs: adding referential constraint to an entity type

查看:158
本文介绍了breezejs:向实体类型添加引用约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我之前的问题的后续问题 - 这个有点混乱,与Telerik数据服务更相关。

This is a follow-up question to my previous issue - this one was getting a bit messy and is more related to the Telerik Data Service.

我从服务器收到的元数据缺少关联节点中的引用约束, 虽然我已经在我的模型上设置了外键属性

The metadata I receive from the server are missing the referential constraints in the association node, although I've set the foreign key attribute on my model.

因此我考虑在回调中手动将这些约束添加到我的实体of FetchMetadata。

Therefore I was thinking about manually adding these constraints to my entities in the callback of FetchMetadata.

这是可能的,有人可以提供一个如何做的简单示例吗?

Is that possible and can someone provide a simple example on how to do it ?

这是我到目前为止所拥有的:

Here's what I have so far:

  manager.fetchMetadata().then(function () {
        var mandatType = manager.metadataStore.getEntityType("Mandate");
        mandatType.autogeneratedKeyType = breeze.AutoGeneratedKeyType.Identity;

        var openPositionsProp = new breeze.NavigationProperty({
            name: "OpenPositions",
            entityTypeName: "OpenPositions:#DirectDebitModel", 
            isScalar: true,
            associationName: "OpenPosition_Mandate_Mandate_OpenPositions",
            foreignKeyNames: ["Id"]
        });

        mandatType.addProperty(openPositionsProp);
});

但它引发了异常:

'Mandate:#DirectDebitModel'EntityType已经添加到MetadataStore中,因此不会向其添加其他属性。

推荐答案

好的,我现在可以使用一种可能的方法。

Ok, I have a possible approach that you might be able to use right now.


  1. 像现在一样从Teleriks OData Feed中获取元数据。

  1. Fetch the metadata from Teleriks OData feed just like you do now.

通过 MetadataStore.exportMetadata 方法导出作为上一步结果创建的metadataStore。这将以Breeze的原生格式返回相同元数据的stringifiedjson。这种格式更容易使用。

Export the metadataStore created as a result of the previous step via the MetadataStore.exportMetadata method. This will return "stringified" json for the same metadata in Breeze's native format. This format is much easier to work with.

通过 JSON.parse 将此字符串转换为json。

Convert this string to json via JSON.parse.

修改json以添加参照约束信息。请参阅此处的Breeze Native Metadata格式文档

Modify the json to add referential constraint information. See Breeze Native Metadata format docs here

创建一个新的MetadataStore并将修改后的json导入其中。

Create a new MetadataStore and import the modified json into it.

使用此MetadataStore创建一个新的EntityManager并使用它。此EntityManager现在应具有完整的Breeze元数据,以便与其余Feed一起使用。

Create a new EntityManager with this MetadataStore and use it. This EntityManager should now have complete Breeze metadata for use with the rest of the feed.

希望这是有意义的!

我们计划在下一版本中发布一种混合元数据。遗憾的是,它并未涵盖您的案例,因为我们专注于如何将自定义元数据添加到现有的metadataStore,而不是实际编辑/修改现有的元数据。

We are planning on releasing a form of hybrid metadata in the next release. Unfortunately, it doesn't cover your case because we are focusing on how to add custom metadata to an existing metadataStore, and not actually edit/modify the existing metadata.

另一种选择是我们(IdeaBlade)为这类工作提供咨询。我们可能会为您编写一个为第1步到第6步执行的工具。如果感兴趣,请联系breeze@ideablade.com并提及此帖子。

Another alternative is that we (IdeaBlade) do offer consulting for this type of work. We could probably write a tool that does steps 1 thru 6 for you. Please contact breeze@ideablade.com if this is of interest and mention this post.

这篇关于breezejs:向实体类型添加引用约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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