0

I guess I'm doing it all wrong but did not find practicle examples to prove the theory.

I have the following code

BusinessLayer

public static void AddEntities(ENTITY entity, int nb) {
    using(TransactionScope scope = new TransactionScope()) {
        for (int i = 0 ; i < nb ; i++) {
            DAL.AddEntity(entity);
        }
        scope.Complete();
    }
}

DataAccessLayer

public static void AddEntity(entity) {
    using(SqlCommand command = ...) {
        // code
        command.ExecuteNonQuery();
    }
}

If an exception is thrown and multiple entities have already been persisted, they are not rollback. But the rest is not persisted also. I need everything to get persisted or nothing.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89

0 Answers0