1

I am looking for a way to export breeze entities on the server side to a json string which a breezejs manager can import from the client side. I looked all over the breeze APIs (both public and internal source code) but I couldn't find an obvious way of achieving this. There is a possibility of getting the desired results by using BreezeSharp (a .NET breeze client) on the server side but I would like to see if this is achievable with using the breeze server APIs only.

GETah
  • 20,922
  • 7
  • 61
  • 103
  • The server responds to a query with JSON-serialized entities, and the EntityManager on the client reads the entities into its cache. Isn't this the normal Breeze query scenario? What am I missing? – Steve Schmitt Dec 08 '15 at 23:16
  • Hi Steve, nope you are not missing anything :) What I am trying to achieve is a bit different. I want to send a few changes triggered by an external event (webhook) in real time down to my javascript clients as json data which can be imported via the manager on the client side. – GETah Dec 09 '15 at 00:02
  • Ah, so you want to use manager.importEntities to bring in what you get from the server. So you need the server to put together the import bundle. What technology stack are you using on the server? – Steve Schmitt Dec 09 '15 at 08:03
  • @SteveSchmitt That's right :) I was changes that get triggered as a result of the external event to be serialized and sent to the connected clients as a string to be imported (this will be done with a signalr channel). The server end is C# ASP.NET MVC 4 – GETah Dec 09 '15 at 10:27

1 Answers1

1

First you need to determine the shape of the bundle to be imported, i.e. something that manager.importEntities will understand. I don't think the format is documented, but you can reverse-engineer it by using:

var exported = manager.exportEntities(['Customer', 'Product'], {asString:true, includeMetadata:false});

Then pretty-print the value of exported to see the data format. See EntityManager.exportEntities for more info.

Once you have that, you can re-create it on the server. In C#, you can build it up using Dictionary and List objects, then serialize it using Json.NET.

An alternative approach would be to have your webhook just tell the client to initiate a query to retrieve the data from the server.

Steve Schmitt
  • 3,124
  • 12
  • 14