I have a list of test objects that are displayed on my page, I would like to be able to add new entities to this list using breeze.
The first thing that I do is prime the current data from the server using the following code:
var getTestObjects = function (testObjects) {
var query = EntityQuery.from('TestObject');
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
if (testObjects) {
testObjects(data.results);
}
datacontext.testObjects = getLocal('TestObject');
};
};
function getLocal(resource) {
var query = EntityQuery.from(resource);
return manager.executeQueryLocally(query);
}
Next I call the Create method for the object:
var createTestObject = function (initialValues) {
var testObjectType = manager.metadataStore.getEntityType("TestObject");
var newTestObject = testObjectType.createEntity(initialValues);
return manager.addEntity(newTestObject);
};
datacontext.createTestObject({ name: 'test' });
datacontext.saveChanges();
All this works fine and the entity is added to the database, however when I call datacontext.testObjects
(the locally available entities), it doesn't have the newly added item. Should this be available or do I have to get the data from the server again?