在微风中创建复杂类型的未绑定实例的正确方法是什么? [英] What's the correct way to create an unbound instance of a complex type in breeze?

查看:47
本文介绍了在微风中创建复杂类型的未绑定实例的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,请设想以下模型:

So imagine the following model:

class ComplexTypeA
{
    public string ComplexPropertyA
}

class ParentTypeA
{
    public string ParentPropertyA
    public ComplextTypeA ParentPropertyB
}

现在进入客户端的微风世界,假设由于种种原因,我需要创建ComplextTypeA和'attach'的实例(我知道它没有附加,它是在复制值,但想不出另一个更好的词),稍后将其复制到我单独创建的ParentTypeA实例中。

Now moving into the breeze world on the client-side, assume that for various reasons I need to create an instance of ComplextTypeA and 'attach' (I know it's not attaching, it's copying values, but can't think of another better word) it later to an instance of ParentTypeA I created separately.

简而言之,最好的方法是这个?我已经设法实现了,但是目前,它是这样的:

Simply put, what's the best way to do this? I have managed to achieve it, but at the moment, it's something like this:

manager.metadataStore.getEntityType('ParentTypeA').complexProperties[0].dataType.createInstance()

如果这是正确的方法,那就很酷,我会给自己一个金星。尽管我担心文档会使它看起来容易很多,但我刚刚找到了一种新颖的创造性方式来以后将自己击倒。

If this is the correct way, then cool, and I'll give myself a gold star. I'm worried though that the documentation makes it seem a lot easier, and I've just found a new and creative way to shoot myself in the foot later.


这实际上有点不正确,您可以使用 complexType.createInstance 方法
创建complexType的未绑定
实例。但是,当您分配它时,您只需将其值复制到
现有实例中即可。

This is actually slightly incorrect, you can create an ‘unbound’ instance of a complexType with the complexType.createInstance method but when you assign it, you are simply copying its values onto an existing instance.

谢谢!

推荐答案

请参阅ComplexType.createInstance方法: ComplexType api

See the ComplexType.createInstance method: ComplexType api.

示例如下:

    // The MetadataStore.getEntityType method returns both EntityTypes and ComplexTypes.
    var locationType = myEntityManager.metadataStore.getEntityType("Location");
    // creates a newLocation complex object with all default values
    var newLocation = locationType.createInstance();
    // or create a fully fleshed out version.
    //  var newLocation = locationType.createInstance( { city: "San Francisco", street: "111 Main Street", state: "CA" });         

这篇关于在微风中创建复杂类型的未绑定实例的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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