2
votes

I've been trying for some time now to use breeze and OData.

My OData comes from another server, and CORS is enabled. I believe the problem is with breeze and odata because I've tested everything using breeze and web api and it worked just fine.

In chrome in network tab I see that OData is fetched properly but for some reason data isn't shown and I get this strange error:

[Q] Unhandled rejection reasons (should be empty): 
[Error]
 q.js:891
Error: OK Logger.js:52


Here is my breeze DataService:

app.adminMuscleGroup.dataService = ( function(breeze, logger) {



    breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);

    var service = new breeze.DataService({
        serviceName: "http://localhost:23758/odata/",
        hasServerMetadata: false,

    });

    breeze.config.initializeAdapterInstance("dataService", "OData");


    var manager = new breeze.EntityManager({ dataService: service });

    manager.enableSaveQueuing(true);

    var dataService = {
        getAll: getAll,
    };

    return dataService;

    function getAll() {
        var query = breeze.EntityQuery.from("MuscleGroup").orderBy("Name");

        return manager.executeQuery(query);
    }

Here is Controller.js:

app.adminMuscleGroup.controller('AdminMuscleGroupCtrl', function ($scope) {

    var dataService = window.app.adminMuscleGroup.dataService;
    var logger = window.app.logger;

    $scope.items = [];

    $scope.getAllMuscleGroups = function() {
        dataService.getAll()
            .then(querySucceeded)
            .fail(queryFailed);
    };

    $scope.getAllMuscleGroups();

    function querySucceeded(data) {
        $scope.items = [];
        data.results.forEach(function(item) {
            $scope.items.push(item);
        });

        $scope.$apply();

        logger.info("Fetched all Muscle Groups");
    }

    function queryFailed(error) {
        logger.error(error.message, "Query failed");
    }

})

Here is screenshot of Console log:

enter image description here

3
Can you show your logger.js file?PW Kad
Sure, it is same as in Breeze ToDo samplehyperN
can you adjust your query and see what is returned - return manager.executeQuery(query).fail(function(error) { logger.error(error.message, ''); }); - I want to see if there is an error thrown that is unhandled from the queryPW Kad
Now it says: Error: Cannot read property 'results' of undefinedhyperN
And I've also added controller.js where I call dataServicehyperN

3 Answers

2
votes

I found out that breeze doesn't work correctly when using regular EntitySetControllers for OData and CORS as you can see in the question I asked here, and that to get them to work the controller should be a regular ApiController decorated with the BreezeControllerAttribute from Breeze.WebApi. It might have already been updated to work but I haven't tried it in a while.

1
votes

Generally when I see 'should be empty' it means that the promise contained a rejection that was unhandled, some other unhandled error, or a promise was simply never returned for some reason. Generally when I have this error I make sure to either console.log() the rejection reason or use something like the logger that you are using. You can do this a number of ways but this should give you the reason for rejection, provided that you aren't using a synchronous query such as executeQueryLocally -

function getAll() {
    var query = breeze.EntityQuery.from("MuscleGroup").orderBy("Name");

    // added a promise failure handler 
    return manager.executeQuery(query).fail(queryFailed);
}

And add the following to your dataservice or w/e

function queryFailed(error) {
    var msg = 'Error retrieving data. ' + error.message;
    logger.logError(msg, error, 'Data call', true);
}

Edit

Ok, so now we know that something is going wrong when we are working with the data, lets see what is being returned -

Edit 2

Sounds like the issue is going to need the magical powers of Ward and Jay - Good luck!

0
votes

You just need to add this extra parameter "DataServiceVersion, MaxDataServiceVersion" configuring enableCors.

config.EnableCors(new EnableCorsAttribute("", "", "*", "DataServiceVersion, MaxDataServiceVersion"));