Tell EntityFramework 6.x , please, how to implement Rollback using EntityFramework 6.x , as well as the Unit of work pattern. For this there is a class interface IUnitOfWork
public interface IUnitOfWork : IDisposable { void Commit(); // void Rollback(); } and class - UnitOfWork
public class UnitOfWork : IUnitOfWork { public DbContext Context { get; private set; } public UnitOfWork(DbContext context) { Context = context; } public void Commit() { if (Context != null) { Context.SaveChanges(); } } public void Dispose() { if (Context != null) { Context.Dispose(); } } } I know that at the T-SQL level, this is defined as follows:
BEGIN TRANSACTION // ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ Π²Π·Π°ΠΈΠΌΠΎΠ΄Π΅ΠΉΡΡΠ²ΠΈΡ IF (@@error <> 0) ROLLBACK COMMIT UPD
It is planned to be used as
try { repository.Delete(...); unitOfWork.Commit(); } catch { unitOfWork.Rollback(); // ΡΠ΅Π³ΠΈΡΡΡΠ°ΡΠΈΡ ΠΎΡΠΈΠ±ΠΊΠΈ }