【问题标题】:What's the correct way to create an unbound instance of a complex type in breeze?在微风中创建复杂类型的未绑定实例的正确方法是什么?
【发布时间】:2013-07-10 02:11:42
【问题描述】:

想象一下下面的模型:

class ComplexTypeA
{
    public string ComplexPropertyA
}

class ParentTypeA
{
    public string ParentPropertyA
    public ComplextTypeA ParentPropertyB
}

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

简单地说,最好的方法是什么?我设法实现了它,但目前,它是这样的:

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

如果这是正确的方法,那就酷,我会给自己一颗金星。我很担心文档让它看起来容易多了,而且我刚刚找到了一种新的、有创意的方法来让我自己在脚下开枪。

这其实有点不对,可以创建一个‘unbound’ 使用 complexType.createInstance 方法的 complexType 实例 但是当你分配它时,你只是将它的值复制到一个 现有实例。

谢谢!

【问题讨论】:

  • 我也有同样的问题。

标签: breeze


【解决方案1】:

查看 ComplexType.createInstance 方法: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" });         

【讨论】:

  • 太好了,谢谢。我不确定 getEntityType 的行为是否如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
  • 2011-01-19
  • 2012-06-01
  • 1970-01-01
  • 2021-08-24
  • 1970-01-01
相关资源
最近更新 更多