© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
30 replies
Core

✅ EF SaveChanges in transactions

Hello,
Does it make a difference if
SaveChanges
SaveChanges
is called after each
Add
Add
operation or only one time after the last
Add
Add
operation?

Multiple times
await using var transaction = await _dbContext.Database.BeginTransactionAsync();
            
await _dbContext.Domains.AddAsync(domain);
await _dbContext.SaveChangesAsync();

await _dbContext.DomainVerifications.AddAsync(domainVerification);
await _dbContext.SaveChangesAsync();

await transaction.CommitAsync();
await using var transaction = await _dbContext.Database.BeginTransactionAsync();
            
await _dbContext.Domains.AddAsync(domain);
await _dbContext.SaveChangesAsync();

await _dbContext.DomainVerifications.AddAsync(domainVerification);
await _dbContext.SaveChangesAsync();

await transaction.CommitAsync();



One time
await using var transaction = await _dbContext.Database.BeginTransactionAsync();
            
await _dbContext.Domains.AddAsync(domain);
await _dbContext.DomainVerifications.AddAsync(domainVerification);

await _dbContext.SaveChangesAsync();
await transaction.CommitAsync();
await using var transaction = await _dbContext.Database.BeginTransactionAsync();
            
await _dbContext.Domains.AddAsync(domain);
await _dbContext.DomainVerifications.AddAsync(domainVerification);

await _dbContext.SaveChangesAsync();
await transaction.CommitAsync();
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ EF core transactions in PostgreSQL
C#CC# / help
2y ago
EF Core Sqlite Add & SaveChanges not working
C#CC# / help
2y ago
EF Core Transaction in both SaveChanges and SqlQueryRaw for Unit Test
C#CC# / help
2y ago
Dbcontext and SaveChanges()
C#CC# / help
5mo ago