Skip to content Skip to sidebar Skip to footer

How To Implement SaveChanges With Breeze Js And Nancy

I have an Angular JS application with Breeze and Nancy (self-hosted with Owin). I've figured out how to get data from server with Breeze, but now I'm trying to save changes using B

Solution 1:

You can just return the incoming saveBundle -- almost. When the Breeze client receives the save response from the server, it expects it to have two properties: entities and keyMappings. The entities are included in the saveBundle already, but you'll need to add the keyMappings array (which can be empty).

The incoming saveBundle looks like this:

{
  "entities": [
    {
      "OrderId": "4b143db9-6dd4-4c0e-90eb-97520d3694ac",
      "CustomerId": "9ef1c520-318a-4b8a-b99d-cb9f6bdb22cc",
      "OrderDate": "2015-01-30T08:00:00.000Z",
      "entityAspect": {
        "entityTypeName": "Order:#Northwind.Model",
        "defaultResourceName": "Orders",
        "entityState": "Added",
        "originalValuesMap": {
        },
        "autoGeneratedKey": null
       }
    },
    {
     ...more entities...
    }
  ],
  "saveOptions": {
    "tag": "whatever"
  }
}

The outgoing saveResult looks like this:

{
  "entities": [
    {
      "OrderId": "4b143db9-6dd4-4c0e-90eb-97520d3694ac",
      "CustomerId": "9ef1c520-318a-4b8a-b99d-cb9f6bdb22cc",
      "OrderDate": "2015-01-30T08:00:00.000Z",
    },
    {
     ...more entities...
    }
  ],
  "keyMappings": [
  ]
}

Note that the incoming saveBundle has an entityAspect on each entity that describes the entity. The saveResult does not need this, but it's not harmful and will be ignored on the client, as will the saveOptions.

These formats are documented in the DataServiceAdapters section of the Breeze documentation, but it's understandable that you didn't find them.


Post a Comment for "How To Implement SaveChanges With Breeze Js And Nancy"