Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda