public void Test2() { using (var dbContext = new ZaabeeDbContext(GetMySqlConn())) { var myDomainObject = CreateDomainObject(); //Your database code here //UoW have no effect here as Begin() is not called. var myRepository = new MyRepository(dbContext.UnitOfWork); myRepository.Insert(myDomainObject); } }
public void Test1() { using (var dbContext = new ZaabeeDbContext(GetPgConn())) { var unitOfWork = dbContext.UnitOfWork; unitOfWork.Begin(); try { var myDomainObject = CreateDomainObject(); //Your database code here var myRepository = new MyRepository(unitOfWork); myRepository.Insert(myDomainObject); //You may create other repositories in similar way in same scope of UoW. unitOfWork.Commit(); } catch { unitOfWork.Rollback(); throw; } } }