Comments (13)
Looking for exactly this. I am using repository pattern with EF 7 and have a method where all my DB updates happen. I'd like to wrap all of these DB calls (Repository.Add + SaveChanges) into a single transaction so if anything fails everything rolls back for all repositories for that particular set of data.
With what I've read it's currently not supported. Any work around at this time?
from entityframework.docs.
In RC1 you would need to use context.Database.BeginTransaction()
/UseTransaction()
to setup using the same transaction for multiple contexts. If all the data is being saved thru a single context instance, then it is already transactional.
from entityframework.docs.
Hi,
We may have also these scenarios:
- Multiple dbcontext type with single connection string (same database, different contexes)
- Multiple dbcontext type with multiple database (each dbcontext targets to a different database, in different server or same server)
- Single dbcontext type with multiple database (for example, a multi-tenant app which has a single dbcontext type but each tenant has it's own database), so there will be multiple instances of same dbcontext type in a unit of work
For such requirements, how can we create a transaction that will be shared by all these contexes :) Will EF Core support that?
from entityframework.docs.
Any idea? Thanks.
from entityframework.docs.
Hey,
First bullet point is covered in https://docs.efproject.net/en/latest/saving/transactions.html#cross-context-transaction-relational-databases-only. The other two would use the same technique, except you would need to use DbConnection.EnlistTransaction(...)
since you would need two separate connections. The one disclaimer is that I haven't actually tried that, but I see no reason that it shouldn't work.
~Rowan
from entityframework.docs.
Thank you so much for leading me, and sorry for not finding the document before.
Have a nice day.
from entityframework.docs.
Closing as we have docs now - https://docs.efproject.net/en/latest/saving/transactions.html
from entityframework.docs.
Have any Multiple dbcontext type with multiple database (each dbcontext targets to a different database, in same server)
demo code? I have not found any about your say DbConnection.EnlistTransaction(...)
hope your help, thanks!
from entityframework.docs.
Have any about Multiple dbcontext type with multiple database (each dbcontext targets to a different database, in same server)
demo code? or more help links?
hope your help, thanks!
from entityframework.docs.
@xyting I don't have demo code.
from entityframework.docs.
@hikalkan Have any opinion about @rowanmiller point DbConnection.EnlistTransaction(...)
?
from entityframework.docs.
Maybe he is saying UseTransaction. He can answer better :)
from entityframework.docs.
Via the Database APIs you can only share a single transaction if you use the same connection, which won't work if you are targeting different databases. You probably want to spin up two transactions and then call Commit()
on both once the operations succeed.
from entityframework.docs.
Related Issues (20)
- "Update" code sample is really Add HOT 2
- Problem with instslling Entity Framework SQL Server HOT 2
- StringToNumberConverter HOT 1
- Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[mywebsite.Data.ApplicationDbContext]' while attempting to activate 'mywebsite.Data.ApplicationDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 HOT 6
- Add back setter for scaffolded collection navigations HOT 4
- Typo in link redirects to wrong site HOT 3
- s
- VS Community 2022 cannot install dotnet-ef when i try to publish. HOT 1
- Document ListValueComparer breaking change
- Document MsBuild integration
- Documentation improvement about data-seeding
- Concerning DbContext disposal HOT 1
- missing defaults information HOT 1
- I cant make use of the Entity.FrameworkCore HOT 1
- Missing doc about Primitive Collections HOT 1
- Doc does not address the most common use-case, when DbContext is injected
- Entity Framework Core 9 HOT 2
- AddRange & Internal Snapshot Method Missing Info
- Primitive Collection Must Implement IList
- Please provide some code samples how to use it in reality. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityframework.docs.