Async extension methods within a transaction?
Issue #61
resolved
Is it possible, in a transaction, to use SQLITE async extension methods such as InsertOrReplaceWithChildrenAsync?
The following is disallowed and directs us to use SQLiteConnection instead:
await db.RunInTransactionAsync ( ( SQLite.Net.Async.SQLiteAsyncConnection tran ) =>
However with the following, tran offers only sync methods:
await db.RunInTransactionAsync ( ( SQLite.Net.SQLiteConnection tran ) => { var x = new X(); tran.Insert (x); var y = new Y(); tran.Insert (y); });
Comments (3)
-
-
You are missing
using SQLiteNetExtensions.Extensions;
for the synchronous operations in SQLiteConnection. -
- changed status to resolved
- Log in to comment
Due to the nature of SQLite.Net async, only synchronous operations are supported inside a transaction. Otherwise, any failed operation between the begin and the end of the transaction may make the transaction to rollback even when the operation was not inside the transaction block.
This is not a SQLite-Net Extensions limitation, but a SQLite.Net one. You can still access to all SQLite-Net Extensions synchronous operations, like
InsertOrReplaceWithChildren
.