如何实现与微风js和南希的SaveChanges [英] How to implement SaveChanges with Breeze js and Nancy

查看:116
本文介绍了如何实现与微风js和南希的SaveChanges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有微风和南希(自托管与Owin)的角度JS应用程序。
我已经想通了如何从服务器微风获取数据,但现在我想保存使用微风变化,有它的问题。
我见过MVC的例子,如:

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 Breeze and have problems with it. I've seen MVC examples like:

[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
    return _repository.SaveChanges(saveBundle);
}

但很明显,我不能做同样的南希。我的应用程序发送POST请求的SaveChanges但随后打破类型错误:未定义不是一个函数无法读取未定义的属性'地图'

目前,我简单地返回相同的Json我的请求得到的,因为我不知道的反应应该是什么:

At the moment I simply return the same Json I get in Request, as I have no idea what the response should be:

Post["/breeze/SaveChanges"] = parameters =>
{
    string response = "failed";
    try
    {
        response = new StreamReader(this.Request.Body).ReadToEnd();
    }
    catch (Exception ex)
    {
         //TODO handle
    }
    return Response.AsJson(response);
};

我不知道,如果它打破,因为从服务器收到请求不正确或者是因为我没有正确设置的东西了。

I'm not sure if it breaks because it receives incorrect request from server or because I haven't set something up correctly.

任何人都可以帮助?

推荐答案

您可以只返回传入 saveBundle - 几乎的。当微风客户端从服务器保存的响应,它期望它有两个属性:实体 keyMappings 。这些实体包括在saveBundle了,但你需要添加keyMappings阵列(可以为空)。

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).

传入saveBundle看起来是这样的:

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"
  }
}

即将离任的saveResult看起来是这样的:

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": [
  ]
}

请注意传入saveBundle有一个 entityAspect 上描述实体每个实体。该saveResult不需要这个,但它不是有害的,并且在客户端将被忽略,也将在 saveOptions

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.

这些格式记录在 DataServiceAdapters 微风文档的部分,但它是可以理解的,你没找到他们。

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

这篇关于如何实现与微风js和南希的SaveChanges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆