Recommended practice for recursive saves and transactions

Posts   
 
    
adhalejr
User
Posts: 18
Joined: 23-Sep-2005
# Posted on: 24-Feb-2006 21:04:41   

I'm using the .net 2.0 templates, 2-class self-servicing, with SQL Server.

I'm creating an object graph with a single root object, a number of new objects in one of its collections, with each of those new objects also getting a new 1:1 object instance as well as other new objects in one of their collections.

Now I want to recursively save the graph - rootEntity.Save(true); - within a single database transaction. I see some superficial comments in the docs that a recursive save internally uses a single DB transaction. Does that mean I don't have to explicitly create a transaction and add each of the new objects to it? If I do need an explicity transaction, can I just add the root object, or do all of the new objects need to be added?

Thanks!

Donnie

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-Feb-2006 02:41:43   

You are right you don't need to create your own transaction. You just call rootEntity.Save(true) and a transaction is created and used to save the rootEntity and all related dirty entites. If you want to make this part of a transaction that is already taking place and locking the tables that the save will be updating then you add the rootEntity to that transaction and then call the save.