0
votes

I am querying the server to get an entity with expand

function _loadIncidents() {
    var deffered = Q.defer(),
        queryObj = new breeze.EntityQuery().from('Incidents').expand(['Deployments', 'IncidentComments', 'DTasks', 'ExtendedProperties', 'IncidentEvents']);

    dataRepository.fetchEntitiesByQuery(queryObj, true).then(function (incidents) {
        var query = breeze.EntityQuery.from("DTasks"),
            incidentIds = dataRepository.getEntitiesByQuerySync(query);

        deffered.resolve();
    }, function(err) {
        deffered.reject(err);
    });

    return deffered.promise;
};

I am getting the results and all is fine, how ever when I query breeze cache to get the entities - I am getting empty collection. So when using expand does the expanded entities are added to the cache?

2
What is the point of your deferred? Why not simply return the promise from dataRepository.fetchEntitiesByQuery? - Ward

2 Answers

0
votes

Yes the related entities identified in the expand should be in cache ... if the query is "correct" and the server interpreted your request as you intended.

Look at the payload of the response from the first request. Are the related entities present? If not, perhaps the query was not well received on the server. As a general rule, you want to make sure the data are coming over the wire before wondering whether Breeze is doing the right thing with those data.

I do find myself wondering about the spelling of the items in your expand list. They are all in PascalCase. Are they these the names of navigation properties of the Incident type? Or are they the names of the related EntityTypes? They need to be former (nav property names), not the latter.

0
votes

I Had problem with the navigation property - as I am not using OData webapi not using EF , there is problem with the navigation properties so for the current time i just wrote

 Object.defineProperty(this, 'Deployments', {
        get: function () {

            return (this.entityAspect && this.entityAspect.entityManager) ?
                this.entityAspect.entityManager.executeQueryLocally(new breeze.EntityQuery("Deployments").
                where('IncidentID', 'eq', this.IncidentID)) :
            [];
        },
        set: function (value) { //used only when loading incidents from the server
            if (!value.results) {
                return;
            }
            var i = 0,
                dataRepository = require('sharedServices/dataRepository');
            for (i; i < value.results.length; i++) {
                dataRepository.addUnchangedEntity('Deployment', value.results[i]);
            }
        },
        enumerable: true
    });