Question

According to documentation, EF6 implicitly wraps ObjectContext.SaveChanges() in transaction. Documentation on DbContext.SaveChanges() says nothing about transactions.

When I tried to test DbContext.SaveChanges() with SQL Server, I saw couple of my inserts in SQL profiler and no transaction operations at all. There was single "audit login" on start containing "set implicit_transactions off".

Have I missed some configuration value or this behavior is "by design" in code-first?

Était-ce utile?

La solution

SaveChanges does execute in one transaction, guaranteed. I think it's a big omission that the MSDN docs on DbContext don't mention this. But then, its virtually useless anyway. The ADO.Net Entity Framework blogs are the place to be.

Sql Server Profiler doesn't log transaction events by default. If you want to see those you have to select them when you start a new trace, for instance:

enter image description here

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top