Ignore TransactionScope for specific query

If you wrap your log call inside of another transaction scope with the suppress option enabled, transaction scope will not be used. public override int SaveChanges() { try { return base.SaveChanges(); } catch (Exception ex) { using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) { LogRepo.Log(message); // stuff to log from the context } throw; } }

NHibernate Transactions on Reads

This post from one of the authors might have your answer: Even if we are only reading data, we want to use a transaction, because using a transaction ensure that we get a consistent result from the database. NHibernate assume that all access to the database is done under a transaction, and strongly discourage any … Read more

Unit-Testing Databases

There’s no real way to unit test a database other than asserting that the tables exist, contain the expected columns, and have the appropriate constraints. But that’s usually not really worth doing. You don’t typically unit test the database. You usually involve the database in integration tests. You typically use your favourite automated unit testing … Read more

Trigering post_save signal only after transaction has completed

I think the simplest way is to use transaction.on_commit(). Here’s an example using the models.Model subclass Photo that will only talk to Elasticsearch once the current transaction is over: from django.db import transaction from django.db.models.signals import post_save @receiver(post_save, sender=Photo) def save_photo(**kwargs): transaction.on_commit(lambda: talk_to_elasticsearch(kwargs[‘instance’])) Note that if the transaction.on_commit() gets executed while not in an active … Read more

Refactoring ADO.NET – SqlTransaction vs. TransactionScope

You won’t immediately gain anything by switching your existing code to use TransactionScope. You should use it for future development because of the flexibility it provides. It will make it easier in the future to include things other than ADO.NET calls into a transaction. BTW, in your posted example, the SqlCommand instances should be in … Read more

tech