问题
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