breezejs createEntity未定义 [英] breezejs createEntity is undefined

查看:212
本文介绍了breezejs createEntity未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

里面的AngularJS指令,我分配一个新值到范围的变量:

  $ scope.myPerson = {TiersId:105191,名称:约翰·史密斯};

的渊源$ scope.myPerson是从BreezeJS实体创建的。

分配新值触发$ scope.apply()由AngularJS,然后由BreezeJS截获。这时候,就变得复杂。

好吧,我想通了,我需要用我已经与我的DataContext注册EntityManager的:

  $ scope.myPerson = myDataContext.createPerson({TiersId:105191,名称:约翰·史密斯});  功能createPerson(人){
        返回manager.createEntity(AccountOwner的人);
  }

现在,它在以下code失败:

  proto.createEntity =功能(typeName的,initialValues​​,entityState){
    entityState = entityState || EntityState.Added;
    VAR实体= this.metadataStore
        ._getEntityType(typeName的)
        .createEntity(initialValues​​);
    如果(entityState!== EntityState.Detached){
        this.attachEntity(实体,entityState);
    }
    返回实体;
};

的实体类型是已知的,但createEntity(initialValues​​)函数是不确定的。怎么来的 ?

要更清楚,这里的相关EF映射以及模型类:

 公共类MandateMappings:EntityTypeConfiguration<授权>
{
    公共MandateMappings()
    {
        属性。(M => m.IBAN).HasMaxLength(34).IsFixedLength()IsUni code(假);        物业(M = GT; m.AccountOwner.Name).HasMaxLength(70);
        物业(M = GT; m.AccountOwner.City).HasMaxLength(500);        物业(M = GT; m.CreatedBy).HasMaxLength(30);
        物业(M = GT; m.UpdatedBy).HasMaxLength(30);
    }
}公共类任务:审计
{
    公共字符串IBAN {搞定;组; }    公共AccountOwner AccountOwner {搞定;组; }}公共类AccountOwner
{
    公共字符串名称{;组; }
    公共字符串城{搞定;组; }
}公共抽象类审计
{
    公众的DateTime CreatedDate {搞定;组; }
    公共字符串CreatedBy {搞定;组; }
}


解决方案

编辑:为V 1.3.1的微风现在不支持继承

如果没有更多的方面,我不能肯定,但我猜测,这个问题是微风还没有关于你的EntityType的元数据。通常这是通过你的第一个查询完成的,但如果你是第一次查询之前创建的实体则另一种方法是调用的 EntityManager.fetchMetadata()的方法,而不是在执行任何createEntity电话。在 fetchMetadata 的方法是asynchonous,即返回一个承诺,所以你需要将承诺的,然后部内执行您的通话createEntity。有一对夫妇最近其他微风的帖子与此类似的有更多的细节和例子。

Inside an AngularJS directive, I assign a new value to a scope variable:

$scope.myPerson = { TiersId: 105191, Name: "John Smith" };

Originaly the $scope.myPerson was created from a BreezeJS entity.

Assigning the new value triggers a $scope.apply() by AngularJS, which is then intercepted by BreezeJS. That's when it gets complicated.

[EDIT]

Ok, I've figured out that I need to use the EntityManager that I've registered with my dataContext:

$scope.myPerson =  myDataContext.createPerson({ TiersId: 105191, Name: "John Smith" });

  function createPerson(person) {
        return manager.createEntity("AccountOwner", person);
  }

Now, it fails in the following code:

  proto.createEntity = function (typeName, initialValues, entityState) {
    entityState = entityState || EntityState.Added;
    var entity = this.metadataStore
        ._getEntityType(typeName)
        .createEntity(initialValues);
    if (entityState !== EntityState.Detached) {
        this.attachEntity(entity, entityState);
    }
    return entity;
};

The entity type is known, but the createEntity(initialValues) function is undefined. How come ?

[EDIT]

To make things clearer, here's the relevant EF mapping as well as the model classes:

public class MandateMappings : EntityTypeConfiguration<Mandate>
{
    public MandateMappings()
    {
        Property(m => m.IBAN).HasMaxLength(34).IsFixedLength().IsUnicode(false);

        Property(m => m.AccountOwner.Name).HasMaxLength(70);  
        Property(m => m.AccountOwner.City).HasMaxLength(500); 

        Property(m => m.CreatedBy).HasMaxLength(30);
        Property(m => m.UpdatedBy).HasMaxLength(30);
    }
}



public class Mandate : Audit
{  
    public string IBAN { get; set; }

    public AccountOwner AccountOwner { get; set; }

}

public class AccountOwner
{
    public string Name { get; set; }
    public string City { get; set; }
}

public abstract class Audit
{
    public DateTime CreatedDate { get; set; }
    public string CreatedBy { get; set; }
}

解决方案

Edit: As of v 1.3.1 Breeze now DOES support inheritance.

Without more context I can't be sure, but I'm guessing that the issue is that Breeze does not YET have metadata about your entityType. Normally this is accomplished via your first query, but if you are creating entities before the first query then the alternative is to call the EntityManager.fetchMetadata() method instead BEFORE performing any createEntity calls. The fetchMetadata method is asynchonous, i.e. returns a promise, so you will need to perform your createEntity call inside of the 'then' portion of the promise. There are a couple of other recent 'Breeze' posts similar to this that have more details and examples.

这篇关于breezejs createEntity未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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