Search code examples
asp.net-web-apiodatabreeze

Breeze OData error


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


Solution

  • 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.