Expose a method on the EntityManager to "unwrap" an entity instance (toJS).
There are a few use cases where an entity instance needs to be sent to the server to an MVC API controller (for example for async server side validation); to do this, it is necessary to obtain an unwrapped version of the instance (plain JSON) that contains no internal properties such as entityAspect and uses properties instead of observables (ko.mapping.toJS is not suitable because of the former). Also, because the client configuration allows for a different naming convention, the method should be able to translate the names back to the naming convention originally used by the server.
Such a method already exists inside the EntityManager, is called "unwrapEntities" although it is private; so the suggestion is only moving it to the public interface of the EntityManager.
More details on this suggestion can be found in http://stackoverflow.com/questions/16202485/breeze-js-how-to-transform-a-breeze-entity-to-a-plain-json-object.
-
Peter Steele commented
I would really be able to use this as well.
-
Claus Conrad commented
This would be VERY nice. As a workaround I currently requery (.fromEntities) and .select() the desired attributes, but an .unwrap method would be cleaner
-
Heiko commented
Just to bring this back to memory. Unwrapped entities is a MUST if handling with all things non-breeze and non-knockout like sending to another webservice or just fill some third-party widget with data.
-
Patrick commented
ko.toJS() is a bad choice to use because the entire object graph is crawled and stringified by knockout. The more entities in local cache = the longer stringify takes.
How to fix it?
-
gopheruk commented
+1. Currently trying to unwrap some entities to raw JSON in order to do a diff on them via library such as JsonDiffPatch
-
Steve Brown commented
This is something we could really use. We want to be able to convert our Breeze client Entities to plain JSON and send them down the wire to other non-Breeze WebAPI service controllers. Problem we have encountered is that when using ko.toJS() it blows up with a circular reference error.