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
Many database ADO providers (such as Oracle ODP.NET) do indeed begin distributed transactions when you use TransactionScope
to transact across multiple connections - even when they share the same connection string.
Some providers, (like SQL2008 in .NET 3.5+) recognizes when a new connection is created in a transaction scope that refers to the same connection string, and will not result in DTC work. But any variance in the connection string (such as tuning parameters) may preclude this from occuring - and the behavior will revert to using a distributed transaction.
Unfortunately, the only reliable means of ensuring your transactions will work together without creating a distributed transaction is to pass the connection object (or the IDbTransaction
) to methods that need to "continue" on the same transaction.
Sometimes it helps to elevate the connection to a member of the class in which you're doing the work, but this can create awkward situations - and complicates controlling the lifetime and disposal of the connection object (since it generally precludes use of the using
statement).