create new entity with new entity type in breeze

喜欢而已 提交于 2019-12-13 04:23:48

问题


I'm writing cordova + angular + breeze app where text info from element should be stored in the cash of browser that wraps the app. Accordind to the docs to do so, first I need to create new entity type in breeze. I do the following:

var entityManager = new breeze.EntityManager("api/Northwind");
var newType = new breeze.EntityType({
    shortName: "input"
});

Next I'm trying to create new entity of this type:

var newEntity = newType.createEntity();

This fails with message: "TypeError: Cannot read property '_ctorRegistry' of undefined"

Is seems to be very basic functionality of breeze but I can't get it work for 2 days already. Could anyone help me with that?


回答1:


After created new EntityType, you should attach it to metadataStore to create entities of new type. Your code should look:

var metadataStore = new breeze.MetadataStore();
entityManager= new breeze.EntityManager({
            serviceName: "api/db",
            metadataStore: metadataStore
        });

// if you call fetchMetadata()
entityManager.fetchMetadata().then(function(){
    var newType = new breeze.EntityType({
        shortName: "input"
    });

    entityManager.metadataStore.addEntityType(newType);

    newType.createEntity(...);
    // ...
});

//or just use var metadataStore
var newType = new breeze.EntityType({
    shortName: "input"
});

entityManager.metadataStore.addEntityType(newType);

newType.createEntity(...);
// ...


来源:https://stackoverflow.com/questions/23651431/create-new-entity-with-new-entity-type-in-breeze

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!