Transactions and recursive save

Posts   
 
    
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 19-Feb-2009 05:49:10   

I have multiple multiple updates to perform in a transactions and some of them are for related entities (i.e. Order - OrderDetail). Do I have to explicitly add all the related entities in the transaction or I can simply add the top entity (i.e Order) and call Save(true) and it will automatically add linked objects in the same transaction?

Using the example from help will these operations run in the same transaction?


Transaction transactionManager = new Transaction(IsolationLevel.ReadCommitted, "Test");

try
{
        OrderEntity newOrder = new OrderEntity();
        ....

        OrderDetailsEntity newOrderRow = new OrderDetailsEntity();
        newOrderRow.Order = newOrder;
        .....

        OtherNonRelatedEntity otherEntity = new OtherNonRelatedEntity();
        otherEntity.... change

        transactionManager.Add(newOrder );
        transactionManager.Add(otherEntity );

        newOrder.Save(true);
        otherEntity.Save();

        transactionManager.Commit();
}
...
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Feb-2009 06:08:06   

Exactly. If you save recursively, all the saves performing in the graph will be added to the involved transaction.

David Elizondo | LLBLGen Support Team