问题
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