I have a parent object (part of a DAL) that contains, amongst other things, a collection (List
) of child objects.
When I\'m saving the object b
In your example the TransactionScope is still in the context of a method, you could simply create a SqlTransaction with multiple commands beneath that. Use TransactionScope if you want to move the transaction out of a method, to say, the caller of that method, or if you access multiple databases.
Update: never mind I just spotted the child call. In this situation, you could pass the connection object to child classes. Also, you don't need to manually dispose the TransactionScope - using blocks act like try-finally blocks and will execute the dispose even on exceptions.
Update 2: better yet, pass the IDbTransaction to the child class. The connection can be retrieved from that.