Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Entity Framework - SaveChanges vs Transaction

I have a bit stupid question, but I didn't find an answer.

Is there any difference between a single call to SaveChanges() and a single call to SaveChanges() inside a transaction? (I'm using Entity Framework in .net core 5 application)

I want to create a record in one table and update data in another one.

For example, it would be:

users.Password = "..."

var passwordReset = new PasswordReset(...)

_context.Add(passwordReset);
_context.SaveChanges();

And with transaction:

using (var transaction = _context.Database.BeginTransaction())
{
    users.Password = "..."

    var passwordReset = new PasswordReset(...)

    _context.Add(passwordReset);
    _context.SaveChanges();

    transaction.Commit();
}

I want to ensure, that two queries will complete successfully but I don't know which option would be the best for me.

Thanks in advance

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Is [there] any difference between single call [to] SaveChanges() and [a] single call [to] SaveChanges() inside a transaction? (I'm using Entity Framework in .net core 5 application)

Not really. A single call to SaveChanges() forms its own transaction. Using a transaction is a way to group multiple calls to SaveChanges together so they may all succeed or all fail (or have finer grained control to partly rollback on failure).

See the reference on transactions in EF Core

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!