0
votes

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?

1

1 Answers

0
votes

Your datacontext is not an instance of any Breeze type so I have no idea what your 'datacontext.textobjects' is. But... if you want all of the local entities in an entityManager simply call EntityManager.getEntities(); So in your example use:

var localEntities = manager.getEntities();

For more info see: http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#method_getEntities