Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current transaction from the dbcontext

In Entity Framework 6, under the DbContext class you can get to current transaction by context.Database.CurrentTransaction. However this API doesn't seem like available in EF.Core. How can I retrieve current transaction object from a dbcontext in EF.Core?

like image 819
whoami Avatar asked Feb 05 '23 10:02

whoami


1 Answers

EF Core still lacks many EF6 features, but (slowly) is catching up.

In that regard, I can't say for earlier versions, but in the latest (so far ) v1.1.0 the DbContext.Database CurrentTransaction property is there, so you can use the same code as in EF6 to access it.

like image 92
Ivan Stoev Avatar answered Feb 23 '23 02:02

Ivan Stoev