在没有实体框架的情况下使用微风保存更改 [英] Saving Changes using breeze without Entity Framework

查看:82
本文介绍了在没有实体框架的情况下使用微风保存更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是个轻而易举的初学者,我想将其集成到ASP.net MVC4项目中。

I am beginner in breeze, I want to integrate it into an ASP.net MVC4 project .

我在使用Breeze.js保存数据
,但此帖子未回答问题,希望我们能解决这次

I have the same problem in Saving Data Using Breeze.js but this post did not answer the problem and I hope we can do it this time

问题是我不必使用实体框架,也不知道如何在控制器的SaveChanges方法中替换ContextProvider

The problem is that I don’t have to use Entity Framework and I don’t know how to replace ContextProvider in SaveChanges method in the controller

[HttpPost]
public SaveResult SaveChanges (JObject saveBundle) {

return ContextProvider.SaveChanges (saveBundle);
}

我也尝试使用SaveOptions自定义ressourceName:

I also tried to customize ressourceName by using SaveOptions:

var option = new breeze.SaveOptions ({resourceName 'MyContoller'});

              entityManager.saveChanges (null, optional)
                       . then (
             alert ("ok");


           )
                      . fail (function (e) {

                       alert (e);
                     });

运行时没有问题,但是控制器没有接收到数据!

When I run it no problem starts but the controller does not receive data!

所以我的问题是:
如何在不使用EntityFramework的情况下轻松保存更改?

So my question is: How can I save changes with breeze without using EntityFramework?

请先谢谢您

推荐答案

为解决此问题,我重新定义了savaChanges方法以读取json数据并将其分配给我的对象,但是我不确定正确的方法是:

To solve this problem I redefined savaChanges method to read the json data and assign it to my object, but I'm not sure that it is the right way:

这是我的SaveChanges方法

This is my SaveChanges method

[HttpPost]
        public void SaveChanges(JObject saveBundle)
        {
            JToken jMyObject = saveBundle["entities"];
            MyClass myObject= new MyClass ();
            string state=(string) jMyObject [0]["entityAspect"]["entityState"];
            if (state == "Added")
            {
               myObject.name =
(string) jMyObject [0]["name"];
                CreateEntity(myObject);
        }
    }

这篇关于在没有实体框架的情况下使用微风保存更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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