.net - Don't rollback the transaction on error in Entity Framework -


when error occurs in entity framework operation, ambient transaction aborted , can't use more database work. try open nested transaction scope, example, throws transactionabortedexception saying "the transaction has aborted."

what can prevent when expect errors , know how continue?

using (var scope = new transactionscope()) {     using (var ctx = new mycontext())     {         try         {             var x = ctx.myentities.firstordefault();         }         catch         {             createtable();             // custom ddl command. can't use ef migrations.             // should fail or not help, i'm happy see more exceptions later.         }         // todo: transaction scope aborted!         ctx.myentities.add(...);     }     scope.complete(); } 

i make new dbcontext instance if helps.

sql server not document kinds of exceptions roll transaction. can't make not roll frankly stupid , there no technical reason it. prone continue executing in case of error (then without transaction). also, quite unpredictable kinds of errors roll , ones not.

the transaction not being rolled ef. sql server that.

you can execute raw sql exception handling:

try  yourstatementhere end try catch ... 

this should keep transaction alive.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -