I have the following code:
Public Async Function Convert(schemaProgress As IProgress(Of ProgressReport), membersProgress As IProgress(Of Boolean), indexProgress As IProgress(Of Boolean)) As Task
Try
Using scope As New TransactionScope
Await ConvertRootAsync()
Dim schemaConversion = ConvertSchemaAsync(schemaProgress)
Await ConvertMembersAsync(membersProgress)
Await ConvertIndexAsync(indexProgress)
Await schemaConversion
scope.Complete()
End Using
Catch ex As Exception
Logger.ErrorException("", ex)
Throw New FatalConversionException
End Try
End Function
The various 'Convert' methods use DbContext
's SaveChanges
method to add data to the database.
To test this out I produced a deliberate error in the ConvertMembersAsync method. The code in the Catch
block is handled all right. But the SaveChanges operations that have been performed prior to the Exception are not rolled back.
The underlying provider is that for SQLExpress LocalDb. The connection string:
"Data Source=(LocalDb)\v11.0;Initial Catalog=OurDb;MultipleActiveResultSets=True;Integrated Security=True;AttachDBFilename=|DataDirectory|MyDb.mdf"
What am I doing wrong?