I’m using breeze.js in a SPA and have problem with entities loaded from server. Namely, entity created from metadata (using metadataEntityType.createEntity()) and added to entity manager has all of the properties like server-side model, ready for binding with knockout, and that is cool.
The problem is when I use entityModel.EntityQuery.from("WorkOrders"), the successCallback that I pass to its .then promise gets a data object with results property which contains an array of vanilla js objects where all of the properties with value == null are missing (this is exactly how server sends that data through the wire, but I suppose that it is how is meant to be because breeze has all metadata on the client and does not need all properties to know that they exist).
I have my custom constructor which can make full-fledged knockout object like the one from createEntity(), but I’m thinking that there must be a better way to let breeze handle this for me automatically. I’m not sure if I should add these objects to entity manager as I suppose they should be already there, and I registered my custom constructor to store using entityManager.metadataStore.registerEntityTypeCtor, but that does not change what success callback gets, it is always plain JSON just like it was sent from server.
Update: Code of method which is called on the server to return json payload is
[HttpGet]
public IQueryable<WorkOrder> WorkOrders()
{
return (IQueryable<WorkOrder>)_contextProvider.Context.WorkOrders;
}
As @Jay pointed in its answer & comment, that may be the cause of behavior. This is the JSON payload returned:
[{"$id":"1","$type":"WorkOrders.Domain.Models.WorkOrder, WorkOrders.Domain","Approved":false,"DateModified":"2013-01-02T22:31:20.897","RequestForEstimate":false,"Id":5}]
This issue was caused by a model being in a different namespace than the DbContext/ObjectContext that hosted it. Previously this was documented as a known limitation.
As of v 0.83.2, breeze now allows model namespaces to be different from the DbContext/ObjectContext namespace.
Please confirm if this fixes the issue.
Thanks