-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support opting out of wrapping database operations in a transaction during SaveChanges() #6413
Conversation
Having this on Database makes some sense because we have other transaction APIs that live there. However, we could also consider an overload of SaveChanges that takes this as an argument. This approach could be nice because it makes the effect and scope of the flag very clear - Or, are there other places apart from SaveChanges where this flag has an effect? |
I was following the pattern of AutoDetectChangesEnabled, but I don't have any strong opinion on the API. @divega What do you want the API to look like? |
I had the same question when I reviewed the code yesterday, but I didn't comment because I couldn't come up with anything that felt fundamentally better that what @ajcvickers already put in the PR. FWIW my thinking went more ore less like this:
|
@divega Just to add a data point that we discussed: SaveChanges already has an overload with a parameter (acceptAllChangesOnSuccess). Do we consider obsoleting this and hanging this flag somewhere else? |
Interesting. To me that means there is no clear cut best way to go about this. I tend to think about Anyway I personally don't feel strongly about obsoleting this overload. I just think that adding even more overloads with multiple flags would make things messy. Let's discuss it in person. |
…uring SaveChanges() Issue #6339 ```C# context.Database.AutoTransactionsEnabled = false; ``` Doesn't affect anything done with UseTransaction or BeginTransaction--only prevents EF from creating a transaction automatically. Also some perf improvements for running the transaction tests--previously when running on my machine they would take about 70 seconds. Now they take about 3. But note that most of this is masked when running many tests in parallel.
794e584
to
7b1264b
Compare
this is an interesting option, but what is your guidance around it especially for dealing with "some stuff got persisted, some didn't". I like being able to get as much in as possible and setting the failures aside. We can identify the failed entity but how can we identify what did and didn't get in so we can try those again later? Would we do something like use a log to identify which commands were executed and work from there? Thanks |
@julielerman Guidance is that this is an advanced option that should only be used with extreme care 😄 We added it to support some specific high-throughput scenarios where data integrity was not an essential concern. |
Issue #6339
Doesn't affect anything done with UseTransaction or BeginTransaction--only prevents EF from creating a transaction automatically.
Also some perf improvements for running the transaction tests--previously when running on my machine they would take about 70 seconds. Now they take about 3. But note that most of this is masked when running many tests in parallel.