Last post Oct 30, 2015 01:05 AM by Krunal Parekh
Oct 28, 2015 12:52 PM|maggiemays|LINK
we discovered that the entity model, when saving data saves records without children first even though that is not the order in which a user entered the data.
I read that adding an index would help, but I'm not sure how this would help. Can somebody explain with an example?
Oct 28, 2015 01:04 PM|PatriceSc|LINK
saves records without children first
Not 100% sure to get what you meant. When you have a child table with foreign keys to a parent table, you have to save FIRST the parent row before being able to insert then child rows. Is this what you see? If yes, what is the issue it causes?
Else elaborate a bit on the behavior you see and don't expect (don't see also how indexes would be related to that but maybe I just don't grasp for know what is the behavior you are talking about)
Oct 28, 2015 01:17 PM|maggiemays|LINK
I'm using entity framework. It saves parent records that have no children first even though the data was not entered in that order. I have a grid and when I'm ready to save,
I would have expected the order of the data from the grid to be saved to the database in that order. That's not the case, it's saving records that have no children first.
So, in my grid I have : rec1,rec2(no children), rec3.... After the save, I retrieve the data in this order: rec2,rec1,rec3...
Oct 28, 2015 01:44 PM|PatriceSc|LINK
Ok got it. Which version of EF do you use? So when retrieving data you are ordering explicitely on the identity column and you checked that this value is wrong on the db side?
Oct 28, 2015 02:03 PM|maggiemays|LINK
it's version 4.0. Yes, the data is coming out in the order of the identity column, which is great, except that the data didn't get saved in the order we thought it should.
Other than the order being wrong, there's nothing wrong with the data itself. But, the user would probably expect the data to be returned in the order that he put it in.
I also have other pre-existing data. I also need to convert old data to the new tables, so I'm not sure how to handle this.
Oct 30, 2015 01:05 AM|Krunal Parekh|LINK
as per discussion: "we don't currently track 'when' something was added to the context, and for efficiency reason we don't track entities in order preserving structures like lists. As a result we can't currently preserve the order of unrelated inserts."
If you really want the order to be preserved the work around is to be Identity Insert.