I have the following problem with a simple MVC4 + ko + breeze webapp: the breeze entities returned by a query are simple javascript objects, without ko observables. I inspected the todo sample (which correctly returnes ko observables) and I didn't find the place where breeze is configured to work with ko (and generate observables). I tried adding the following lines, but nothing changed:
var core = breeze.core;
var entityModel = breeze.entityModel;
core.config.setProperties({
trackingImplementation: entityModel.entityTracking_ko,
remoteAccessImplementation: entityModel.remoteAccess_webApi
});
Thanks in advance for Your kind help
My problem was that I have loaded knockout AFTER breeze and therefore breeze returned me POJO objects.
After changing the load order breeze returned KO observables:
@frenchfraso - It may be worth knowing of a few improvements in Breeze since you wrote your code.
The
entityModel
namespace is deprecated and everything that was on it has been elevated tobreeze
. TheentityModel
namespace still works ... but you want to get rid of it when you have the time. Here's how you'd create an EntityManager today:Knockout is now the default "modelLibrary" adapter and Web API is the default "dataservice" adapter so you no longer have to configure breeze core.
That means you can simply delete every line of the code in your question :)
There is a new syntax to specify a non-default Breeze adapter. Here's an example that configures Breeze to use the Backbone model library instead of Knockout:
gotcha! the problem was in a couple of missing attributes in the WebApi controller:
After adding [JsonFormatter, ODataActionFilter] the returned entities had the expected ko observables!