Saving Changes using breeze without Entity Framework

若如初见. 提交于 2019-12-23 03:35:15

问题


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

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

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);
}

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!

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

Thank you in advance


回答1:


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:

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);
        }
    }


来源:https://stackoverflow.com/questions/17767789/saving-changes-using-breeze-without-entity-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!