Reputation: 6752
EDIT for people that stumble upon this question in the future.
This is not a breeze issue, it is an EF issue and has been asked many times on SO. Like here and here.
I am using Breeze with Knockout. I am creating entities and pushing them to an array and when saving the changes to the server the data ends up in a different order than how it was pushed on the client. I am using Web API and Entity Framework.
The Javascript code looks like this:
var owner = manager.createEntity('OwnerInformation');
licApp().owners.push(owner);
Before SaveChanges
is called the array looks like this:
When SaveChanges
is called the saveBundle
looks like this (ommiting a lot of other info for brevity)
{"entities": [
{
"Id": 2008,
{
"Id": -3,
"LicensingApplicationId": 2008,
"FirstName": "First",
"LastName": "Owner",
},
{
"Id": -4,
"LicensingApplicationId": 2008,
"FirstName": "Second",
"LastName": "Owner",
}
]}
but after saving to the database the result is this (the first column is the id):
Why are they being inserted backwards?
Upvotes: 3
Views: 421
Reputation: 17863
I have a higher order question for you. Why do you care? You're using a relational database. Order is not defined. If you care about order, your data should have something to orderBy.
I'm not trying to be snarky. I honestly believe that the expectation of save order sets you up for failure. Convince me otherwise. I'm ready to learn.
p.s.: I don't think Breeze has anything to do with it ... on client or server. I'll bet you're using EF. I've never been able to predict EF's save order ... nor have I bothered to try, given the principles involved.
Upvotes: 3