Can I use SqliteCreateDatabaseIfNotExists within an external transaction?
See original GitHub issueI want to use SqliteCreateDatabaseIfNotExists
within a transaction, but I can’t because SqliteInitializerBase.InitializeDatabase()
creates one while execution. Is there any way to use an external transaction with the initializer?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
SQLiteDatabase nested transaction and workaround
The nested transaction cannot be rolled back itself, because it does not exist apart from the outside transaction.
Read more >SqLite Transactions:Yes, but Ambient Transactions:No?
You currently cannot use ambient System.Transactions.Transaction over multiple data sources (distributed transaction), regardless of database.
Read more >Statements outside of explicit transactions in SQLite
So I tried a test: In one thread, I ran a SELECT statement, but in between retrieving rows (2 at a time) I...
Read more >Transactions - Microsoft.Data.Sqlite
Transactions let you group multiple SQL statements into a single unit of work that is committed to the database as one atomic unit....
Read more >SQLite Transaction Explained By Practical Examples
Learn how to deal with SQLite transactions by using the BEGIN TRANSACTION, COMMIT, and ROLLBACK statements to control transactions.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for your PR. As I look at this, I ask myself whether the first transaction is necessary. The first transaction is to ensure the atomicity of the Database creation. Inside this transaction the
SqliteDatabaseCreator
is called. There I wrote the following code:db.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction, sql);
That this query will always be executed as transaction (either as a new one or the existing will be used). That means also, that your code will not work (there will always be a transaction, which is IMHO how it should be).The solution here is simply to remove the first transaction creation in the initializer. -> The query will be executed always inside a transaction but you can specify your own.
Then there is the second part, the seeding of the data. There its also not necessary to have explicitly a transaction because SaveChanges is only called once, which means there is an implicit transaction.
Therefore, I’ll reject your PR and just delete the unnecessary code. It would be great if you can test your use case with it.
Version 1.5.2 published. NuGet will list it within one hour.