-
Notifications
You must be signed in to change notification settings - Fork 20
Description
The idea of Mighty transaction support is that you can optionally pass a DbConnection into all Mighty methods, and thus that you can get Mighty methods to automatically work with any transactions which are open on the connection.
Unfortunately SQL Server doesn't work like that! (All other ADO.Net SQL drivers which Mighty supports do.) In SQL Server you have to manually join a DbCommand to a transaction even if the command is operating on a connection which has a transaction open.
There is also no clean, official way to automatically join a DbCommand to the open transaction on a connection.
Fortunately, there is a slightly 'hacky' way to do it, which works and seems to have remained stable for a while, although it is NOT officially supported. As this makes transactions very much easier to work with in SQL Server in Mighty, I have added this code to Mighty and enabled it by default.
- The new flag is called
SqlServerAutoEnlistCommandsToTransactions - It is available in v4 onwards
- If you leave the flag on (default), then to use Mighty commands within a transaction you just have to pass the
DbConnectionwith the open transaction to the Mighty command - Without this support, you have to use
Mighty.CreateCommand, then join the command to the transaction yourself, and then use one of the Mighty variants which takes aDbCommandto execute it; i.e. it's possible, but much more fiddly, without this support - The flag is not required and has no effect on supported databases other than SQL Server, which already work in the non-fiddly way by default, with no custom code required within Mighty