Does the entity structure preserve ordering when inserted into the database?
We are planning on using identity columns in our sql server database. We currently use commands to generate unique identifiers, but ordering appears to matter, which is why we are considering moving to identification codes.
Since the ordering is relevant, we want to make sure that the order in which we add objects to the entity context is also the order in which they are inserted into the database. This matters since sql server will generate values for the identity column.
Is this guaranteed by the entity's infrastructure? If not, what is an effective solution to create your own unique integer ids for the database that is updated from different processes.
a source to share
I'm just guessing here (although it should be pretty easy to check), but I don't think EF can guarantee an order. I'm pretty sure the internal structure is based on the IEnumerable type, probably List, which is simply enumerated at the time of insertion, and the enumeration - as far as I know, is not guaranteed to be in the same order every time.
Instead, I'll add the highlighted "sort order" column to the database table and create a form there.
a source to share
I would not rely on insertion order since the order of your records is being returned. Sure, it will work most of the time, but what if you ever need to insert a string somewhere? I would say that your best bet is to add an ordinal column and actively generate ordinals for each row as you would like them to be returned.
a source to share