Order of saved children in collection

Posts   
 
    
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 22-Sep-2014 17:30:11   

Hi,

Is there a way to force lllgen to guarantee the order of saved items in child entity collection? If I do:

invoice.Rows.Add(row1) invoice.Rows.Add(row2) invoice.Rows.Add(row3)

is it guaranteed to save in that order (and thus rows will have identity column values assigned in that order in SQL Server)?

I'm using llblgen 2.6.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Sep-2014 18:44:12   

Is it saved in a different order?!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 22-Sep-2014 18:54:36   

Robert.W wrote:

Hi,

Is there a way to force lllgen to guarantee the order of saved items in child entity collection? If I do:

invoice.Rows.Add(row1) invoice.Rows.Add(row2) invoice.Rows.Add(row3)

is it guaranteed to save in that order (and thus rows will have identity column values assigned in that order in SQL Server)?

I'm using llblgen 2.6.

The save order is guaranteed to be valid not to violate FK constraints (so PK side is always persisted first). The order in which they're persisted in a single collection is likely that order, but not guaranteed. You shouldn't rely on identity values having a given order: a transaction that rolls back has identity values which will never be re-used (so the sequence of stored values in the table has gaps)

Frans Bouma | Lead developer LLBLGen Pro
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 22-Sep-2014 19:14:29   

Walaa - It turned out that the issue was in my code. It is in fact saving in the order that I'm adding to the child collection.

Frans - I'm not relying on IDs not having gaps. I only needed to have children saved in the order that I add them.

Thanks for the quick response guys.