public void SaveFileTransaction(FileTransferBase file) { try { rx.BeginTransaction(); file.isCompleted = (file.Status == TransferStatus.Completed); RepositoryItem ri = GetRepositoryItem(file); if (ri != null) { ri.Availability = StatusToAvailability(file, ri.Availability); rx.Save(ri); } RepositoryItemVersion riv = GetRepositoryItemVersion(file); if (riv != null) { riv.Availability = StatusToAvailability(file, riv.Availability); rx.Save(riv); } rx.Save(file); rx.Commit(); } catch (Exception ex) { rx.Rollback(); throw ex; } }
/// <summary> /// Handle 'around' advice for services /// </summary> public object Invoke(IMethodInvocation invocation) { object returnValue = null; using (Repository repository = new Repository(Repository.SessionFactory)) { repository.BeginTransaction(); DomainRegistry.Repository = repository; DomainRegistry.Library = null; try { returnValue = invocation.Proceed(); repository.CommitTransaction(); } catch (Exception e) { returnValue = ServiceResult.Error(invocation.Method.ReturnType, e); } } return returnValue; }
public Result GetNextQuestion() { if (this.Current == null || DateTime.Now > this.Expiry) { using (var repository = new Repository()) { repository.BeginTransaction(); var datapoint = repository.GetNextDatapoint(); if (datapoint == null) return null; repository.SetDatapointUsed(datapoint.ID); var related = repository.GetRelatedDatapoints(datapoint.ID); this.Current = new Result(); this.Current.Focus = datapoint; this.Current.Related = related; this.Expiry = DateTime.Now.AddSeconds(Constants.QuestionTimeout); repository.CommitTransaction(); } } this.Current.ExpiresIn = this.Expiry.Subtract(DateTime.Now).TotalSeconds; return this.Current; }
/// <summary> /// Handle 'around' advice for services /// </summary> public object Invoke(IMethodInvocation invocation) { object returnValue = null; using (Repository repository = new Repository(Repository.SessionFactory)) { repository.BeginTransaction(); DomainRegistry.Repository = repository; DomainRegistry.Library = null; try { returnValue = invocation.Proceed(); repository.CommitTransaction(); } catch (Exception e) { returnValue = ServiceResult.Error(invocation.Method.ReturnType, e); } } return(returnValue); }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <param name="model">The model passed in the request's content body.</param> /// <returns>The result of the request.</returns> protected override object PerformRequest(HttpContextBase context, ScheduledJobRecord model) { if (model == null) { throw new ArgumentNullException("model", "model cannot be null."); } if (this.ScheduleId > 0) { model.ScheduleId = this.ScheduleId; using (IDbTransaction transaction = Repository.BeginTransaction()) { try { ScheduleRecord schedule = Repository.GetSchedule(this.ScheduleId, transaction); if (schedule != null) { if ("PUT".Equals(this.Verb, StringComparison.OrdinalIgnoreCase)) { model.Id = Helper.RouteIntValue(1); if (model.Id != null && model.Id > 0) { model = Repository.UpdateScheduledJob(model, transaction); } else { BadRequest(); } } else { model = Repository.CreateScheduledJob(model, transaction); } Repository.SignalWorkers(schedule.ApplicationName, WorkerSignal.RefreshSchedules, transaction); } else { NotFound(); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } } else { BadRequest(); } return(new { Id = model.Id }); }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <returns>The response to write.</returns> protected override byte[] PerformRequest(HttpContextBase context) { if (this.Id > 0) { using (IDbTransaction transaction = Repository.BeginTransaction()) { try { Repository.DeleteSchedule(this.Id, transaction); Repository.SignalWorkers(ApplicationName, WorkerSignal.RefreshSchedules, transaction); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } else { BadRequest(); } return(null); }
public void EditFolder() { using (var repository = new Repository()) { repository.BeginTransaction(tran => { var folders = repository.GetFolderWithSubFolders(1); Console.WriteLine($"Quantity of folders found: {folders.Count}"); Console.WriteLine(); var firstSubFolder = folders.Skip(1).First(); var originName = firstSubFolder.Name; var originHidCode = firstSubFolder.HidCode; Console.WriteLine("First subfolder of the root:"); Console.Write(ToJson(firstSubFolder)); Console.WriteLine(); Console.WriteLine(); firstSubFolder.Name = "ZZZ"; var sw = new Stopwatch(); sw.Start(); var lastSubFolder = repository.SaveFolder(firstSubFolder, withHidReorder: true); sw.Stop(); Console.WriteLine($"Change of Name to ZZZ made the firstSubFolder the last for {sw.Elapsed.TotalMilliseconds.ToString("0.##")} ms:"); Console.Write(ToJson(lastSubFolder)); Console.WriteLine(); Console.WriteLine(); lastSubFolder.Name = originName; sw.Restart(); firstSubFolder = repository.SaveFolder(lastSubFolder, withHidReorder: true); sw.Stop(); Console.WriteLine($"Change of Name to {originName} made the lastSubFolder the first again for {sw.Elapsed.TotalMilliseconds.ToString("0.##")} ms:"); Console.Write(ToJson(firstSubFolder)); Console.WriteLine(); Console.WriteLine(); Assert.AreEqual(originHidCode, firstSubFolder.HidCode); // commit transaction tran.Commit(); }); } // !!!!! SEE CONSOLE OUTPUT !!!!!!!! }
public IHttpActionResult Put(long id, [FromBody] CreateRoleModel model) { using (var t = Repository.BeginTransaction()) { var role = RoleService.UpdateRole(id, model.Name, model.Description); t.Commit(); return(Json(role)); } }
public IHttpActionResult Post([FromBody] CreateRoleModel model) { using (var t = Repository.BeginTransaction()) { Role role = RoleService.CreateRole(model.Name, model.Description); t.Commit(); return(Json(role)); } }
public void Join_example_with_transaction_insert() { Repository.DefaultConnectionString = @"Data source=.\SQLEXPRESS;Initial Catalog=WeenyMapper;Trusted_Connection=true"; Repository.DefaultConvention = new BlogConvention(); var myBlog = new Blog("My blog"); var steve = new User("Steve", "password"); var post1 = new BlogPost("Title 1", "Content 1 goes here") { Blog = myBlog, Author = steve }; var post2 = new BlogPost("Title 2", "Content 2 goes here") { Blog = myBlog, Author = steve }; var post3 = new BlogPost("Title 3", "Content 3 goes here") { Blog = myBlog, Author = steve }; var post4 = new BlogPost("Title 4", "Content 4 goes here") { Blog = myBlog, Author = steve }; using (var repository = new Repository()) { using (var transaction = repository.BeginTransaction()) { repository.Insert(myBlog); repository.Insert(steve); repository.Insert(post1, post2, post3, post4); transaction.Commit(); } repository.Update <BlogPost>() .Set(x => x.Title, "Updated title 2") .Where(x => x.Id == post2.Id) .Execute(); repository.Delete <BlogPost>() .Where(x => x.Id == post3.Id || x.Title == "Title 4") .Execute(); var actualBlog = repository.Find <Blog>().Where(x => x.Id == myBlog.Id) .Join(x => x.Posts, x => x.Blog) .OrderBy <BlogPost>(x => x.Title) .Execute(); Assert.AreEqual("My blog", actualBlog.Name); Assert.AreEqual(2, actualBlog.Posts.Count); Assert.AreEqual("Title 1", actualBlog.Posts[0].Title); Assert.AreEqual("Updated title 2", actualBlog.Posts[1].Title); } }
public IHttpActionResult Post([FromBody] CreateGroupModel model) { using (var t = Repository.BeginTransaction()) { var group = GroupService.CreateGroup(model.Name); t.Commit(); return(Json(group)); } }
public IHttpActionResult ChangePassword(long id, [FromBody] ChangeUserPasswordModel model) { using (var t = Repository.BeginTransaction()) { var user = UserService.ChangePassword(id, model.CurrentPassword, model.NewPassword); t.Commit(); return(Json(user)); } }
public IHttpActionResult Delete(long id) { using (var t = Repository.BeginTransaction()) { ProjectService.DeleteProject(id); t.Commit(); return(Ok()); } }
public IHttpActionResult Delete([FromUri] RemoveUserRoleModel model) { using (var t = Repository.BeginTransaction()) { UserService.RemoveUserRole(model.UserId, model.RoleId); t.Commit(); return(Ok()); } }
public IHttpActionResult Post([FromBody] CreateTokenModel model) { using (var t = Repository.BeginTransaction()) { var authToken = AuthTokenService.Create(model.Username, model.Password); t.Commit(); return(Json(Mapper.Map <AuthTokenCreateView>(authToken))); } }
public IHttpActionResult Post([FromBody] CreateProjectModel model) { using (var t = Repository.BeginTransaction()) { var project = ProjectService.CreateProject(model.Name, model.Description, model.OwnerId); t.Commit(); return(Json(project)); } }
public IHttpActionResult Post([FromBody] CreateUserModel model) { using (var t = Repository.BeginTransaction()) { var user = UserService.CreateUser(model.Username, model.Password); t.Commit(); return(Json(user)); } }
public IHttpActionResult Put(long id, [FromBody] UpdateProjectModel model) { using (var t = Repository.BeginTransaction()) { var project = ProjectService.UpdateProject(id, model.Name, model.Description); t.Commit(); return(Json(project)); } }
/// <summary>Saves or updates an item storing it in database</summary> /// <param name="unsavedItem">Item to save</param> public virtual void Save(ContentItem unsavedItem) { using (var tx = Repository.BeginTransaction()) { tx.Committed += (s, a) => Invoke(ItemSaved, new ItemEventArgs(unsavedItem)); Utility.InvokeEvent(ItemSaving, unsavedItem, this, sources.Save, null); tx.Commit(); } }
public IHttpActionResult Post([FromBody] CreateUserRoleModel model) { using (var t = Repository.BeginTransaction()) { UserRole userRole = UserService.AddUserRole(model.UserId, model.RoleId); t.Commit(); return(Json(userRole)); } }
public void MultipleEntityCompositePrimaryKey() { Repository <Organization> orgRepo = new Repository <Organization>(Fixture.Connection); try { //add organization record Organization org = new Organization() { CustomerCode = "T005", Name = "Bajipura", AccountNum = 123 }; //add address record Address address = new Address() { CustomerCode = "T005", AddressType = "Home", AddressLine1 = "line 1", AddressLine2 = "line 2", }; orgRepo.BeginTransaction(); Repository <Address> addRepo = new Repository <Address>(orgRepo.Transaction); orgRepo.Add(org); address.Id = (long)addRepo.Add(address); //check before commit Assert.Equal(org.CustomerCode, orgRepo.ReadOne <string>("customercode", org.CustomerCode)); Assert.Equal(address.Id, addRepo.ReadOne <long>("Id", new Address() { Id = address.Id, AddressType = "Home" })); orgRepo.Commit(); //cleanup transaction addRepo.Transaction = null; //check after commit Assert.Equal(org.CustomerCode, orgRepo.ReadOne <string>("customercode", org.CustomerCode)); Assert.Equal(address.Id, addRepo.ReadOne <long>("Id", new Address() { Id = address.Id, AddressType = "Home" })); } catch (Exception ex) { orgRepo.Rollback(); Console.WriteLine(ex.Message); Assert.True(false); } }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <param name="model">The model passed in the request's content body.</param> /// <returns>The result of the request.</returns> protected override object PerformRequest(HttpContextBase context, WorkerSignalRecord model) { if (model == null) { throw new ArgumentNullException("model", "model cannot be null."); } if (this.Id > 0) { if (model.Signal == WorkerSignal.Start || model.Signal == WorkerSignal.Stop) { using (IDbTransaction transaction = Repository.BeginTransaction()) { try { WorkerRecord worker = Repository.GetWorker(this.Id, transaction); if (worker != null && worker.ApplicationName == ApplicationName) { worker.Signal = model.Signal; worker.UpdatedOn = DateTime.UtcNow; Repository.UpdateWorker(worker, transaction); } else { NotFound(); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } } else { BadRequest(); } } else { BadRequest(); } return(null); }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <param name="model">The model passed in the request's content body.</param> /// <returns>The result of the request.</returns> protected override object PerformRequest(HttpContextBase context, WorkerRecord model) { if (model == null) { throw new ArgumentNullException("model", "model cannot be null."); } model.ApplicationName = ApplicationName; model.QueueNames = QueueNameFilters.Parse(model.QueueNames).ToString(); model.UpdatedOn = DateTime.UtcNow; using (IDbTransaction transaction = Repository.BeginTransaction()) { try { if ("PUT".Equals(this.Verb, StringComparison.OrdinalIgnoreCase)) { model.Id = Helper.RouteIntValue(0); if (model.Id != null && model.Id > 0) { WorkerRecord existing = Repository.GetWorker(model.Id.Value, transaction); model.Signal = existing.Signal; model.Status = existing.Status; model = Repository.UpdateWorker(model, transaction); } else { BadRequest(); } } else { model = Repository.CreateWorker(model, transaction); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } return(new { Id = model.Id }); }
public void MultipleEntity() { Repository <City> cityRepo = new Repository <City>(Fixture.Connection); try { //add country record Country country = new Country() { Name = "TransactionTests.MultipleEntity", CreatedBy = Fixture.CurrentUserId }; //add city record City city = new City() { Name = "TransactionTests.MultipleEntity", State = "T", CreatedBy = Fixture.CurrentUserId }; cityRepo.BeginTransaction(); Repository <Country> countryRepo = new Repository <Country>(cityRepo.Transaction); country.Id = (long)countryRepo.Add(country); city.CountryId = (int)country.Id; city.Id = (long)cityRepo.Add(city); //check before commit Assert.Equal(country.Id, cityRepo.ReadOne <long>("id", country.Id)); Assert.Equal(city.Id, cityRepo.ReadOne <long>("id", city.Id)); cityRepo.Commit(); //check after commit Assert.Equal(country.Id, cityRepo.ReadOne <long>("id", country.Id)); Assert.Equal(city.Id, cityRepo.ReadOne <long>("id", city.Id)); } catch (Exception ex) { cityRepo.Rollback(); Console.WriteLine(ex.Message); Assert.True(false); } }
public void SingleEntity() { Repository <City> cityRepo = new Repository <City>(Fixture.Connection); try { cityRepo.BeginTransaction(); //add two records in transaction City[] cities = new City[2] { new City() { Name = "Transaction City 1", State = "T", CreatedBy = Fixture.CurrentUserId }, new City() { Name = "Transaction City 2", State = "T", CreatedBy = Fixture.CurrentUserId } }; cities[0].Id = (long)cityRepo.Add(cities[0]); cities[1].Id = (long)cityRepo.Add(cities[1]); //check before commit Assert.Equal(cities[0].Id, cityRepo.ReadOne <long>("id", cities[0].Id)); Assert.Equal(cities[1].Id, cityRepo.ReadOne <long>("id", cities[1].Id)); cityRepo.Commit(); //check after commit Assert.Equal(cities[0].Id, cityRepo.ReadOne <long>("id", cities[0].Id)); Assert.Equal(cities[1].Id, cityRepo.ReadOne <long>("id", cities[1].Id)); } catch (Exception ex) { cityRepo.Rollback(); Console.WriteLine(ex.Message); Assert.True(false); } }
public void Join_example_with_transaction_insert() { Repository.DefaultConnectionString = @"Data source=.\SQLEXPRESS;Initial Catalog=WeenyMapper;Trusted_Connection=true"; Repository.DefaultConvention = new BlogConvention(); var myBlog = new Blog("My blog"); var steve = new User("Steve", "password"); var post1 = new BlogPost("Title 1", "Content 1 goes here") { Blog = myBlog, Author = steve }; var post2 = new BlogPost("Title 2", "Content 2 goes here") { Blog = myBlog, Author = steve }; var post3 = new BlogPost("Title 3", "Content 3 goes here") { Blog = myBlog, Author = steve }; var post4 = new BlogPost("Title 4", "Content 4 goes here") { Blog = myBlog, Author = steve }; using (var repository = new Repository()) { using (var transaction = repository.BeginTransaction()) { repository.Insert(myBlog); repository.Insert(steve); repository.Insert(post1, post2, post3, post4); transaction.Commit(); } repository.Update<BlogPost>() .Set(x => x.Title, "Updated title 2") .Where(x => x.Id == post2.Id) .Execute(); repository.Delete<BlogPost>() .Where(x => x.Id == post3.Id || x.Title == "Title 4") .Execute(); var actualBlog = repository.Find<Blog>().Where(x => x.Id == myBlog.Id) .Join(x => x.Posts, x => x.Blog) .OrderBy<BlogPost>(x => x.Title) .Execute(); Assert.AreEqual("My blog", actualBlog.Name); Assert.AreEqual(2, actualBlog.Posts.Count); Assert.AreEqual("Title 1", actualBlog.Posts[0].Title); Assert.AreEqual("Updated title 2", actualBlog.Posts[1].Title); } }
public void Rollback() { Repository <City> cityRepo = new Repository <City>(Fixture.Connection); try { //add city record which fails as Id is given for Identity column insert for MSSQL City city = new City() { Id = 1, Name = "TransactionTests.Rollback", State = null, CreatedBy = Fixture.CurrentUserId }; //Delete record if exists before transaction if (cityRepo.Exists(city.Id)) { cityRepo.HardDelete(city.Id, Fixture.CurrentUserId); } cityRepo.BeginTransaction(); //add record city.Id = (long)cityRepo.Add(city); //add record with same key to generate error for PGSql city.Id = (long)cityRepo.Add(city); cityRepo.Commit(); Assert.NotEqual("TransactionTests.Rollback", cityRepo.ReadOne <string>("Name", 1)); } catch (Exception ex) { cityRepo.Rollback(); Assert.NotEqual("TransactionTests.Rollback", cityRepo.ReadOne <string>("Name", 1)); Console.WriteLine(ex.Message); } }
protected override async Task SaveAsync(EventLog eventLog) { var perviousVersion = Version - 1; var conditionValue = perviousVersion == 0 ? null : perviousVersion.ToString(); Repository.BeginTransaction(Constants.RobotVersionKey, conditionValue); var eventLogTask = Repository.SaveListAsync(Constants.EventLogsKey, eventLog); var queueTask = Repository.QueuePushAsync(Constants.CommandReceivedQueue, eventLog); var robotStateTask = Repository.SaveAsync(Constants.RobotStateKey, new RobotState { CurrentPosition = _currentPosition, Facing = _facing, Version = Version }); var versionTask = Repository.SaveAsync(Constants.RobotVersionKey, Version.ToString()); var result = await Repository.CommitTransactionAsync(); if (!result) { throw new InvalidOperationException("Inconsistent state"); } }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <param name="model">The model passed in the request's content body.</param> /// <returns>The result of the request.</returns> protected override object PerformRequest(HttpContextBase context, ScheduledJobOrderList model) { if (model == null) { throw new ArgumentNullException("model", "model cannot be null."); } if (this.ScheduleId > 0) { if (model.Numbers.Count > 0) { using (IDbTransaction transaction = Repository.BeginTransaction()) { try { foreach (ScheduledJobOrderRecord record in model.Numbers) { record.ScheduleId = this.ScheduleId; Repository.UpdateScheduledJobOrder(record, transaction); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } } } else { BadRequest(); } return(null); }
private static void CreateBlogTestData() { Repository.DefaultConvention = new BlogConvention(); var myBlog = new Blog("My blog"); var steve = new User("Steve", "password"); var post1 = new BlogPost("Title 1", "Content 1 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2011, 1, 1) }; var post2 = new BlogPost("Title 2", "Content 2 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2012, 1, 5) }; var post3 = new BlogPost("Title 3", "Content 3 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2012, 4, 1) }; var post4 = new BlogPost("Title 4", "Content 4 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2013, 1, 1) }; using (var repository = new Repository()) { using (var transaction = repository.BeginTransaction()) { repository.Insert(myBlog); repository.Insert(steve); repository.Insert(post1, post2, post3, post4); transaction.Commit(); } } }
public void ReparentSubFolders() { using (var repository = new Repository()) { repository.BeginTransaction(tran => { var rootFolder = repository.GetUserRootFolder(14); var folderA = new Folder { ParentId = rootFolder.Id, Name = "A" }; folderA = repository.SaveFolder(folderA, withHidReorder: false); var folderAA = new Folder { ParentId = folderA.Id, Name = "AA" }; folderAA = repository.SaveFolder(folderAA, withHidReorder: false); var folderAAA = new Folder { ParentId = folderAA.Id, Name = "AAA" }; folderAAA = repository.SaveFolder(folderAAA, withHidReorder: false); var folderAAB = new Folder { ParentId = folderAA.Id, Name = "AAB" }; folderAAB = repository.SaveFolder(folderAAB, withHidReorder: false); var folderB = new Folder { ParentId = rootFolder.Id, Name = "B" }; folderB = repository.SaveFolder(folderB, withHidReorder: false); var folderBA = new Folder { ParentId = folderB.Id, Name = "BA" }; folderBA = repository.SaveFolder(folderBA, withHidReorder: false); var folderTree = repository.GetFolderTree(rootFolder.Id); Console.WriteLine("Just created folder tree: "); Console.Write(ToJson(folderTree)); Console.WriteLine(); Console.WriteLine(); folderAA.ParentId = folderB.Id; folderAA = repository.SaveFolder(folderAA, withHidReorder: false); Assert.AreEqual("/2/0/", folderAA.HidPath); folderTree = repository.GetFolderTree(rootFolder.Id); Console.WriteLine("Folder tree after reparent Folder AA to Folder B without Hid reorder: "); Console.Write(ToJson(folderTree)); Console.WriteLine(); Console.WriteLine(); folderAA.ParentId = folderA.Id; folderAA = repository.SaveFolder(folderAA, withHidReorder: false); Assert.AreEqual("/1/1/", folderAA.HidPath); folderAA.ParentId = folderB.Id; folderAA = repository.SaveFolder(folderAA, withHidReorder: true); Assert.AreEqual("/2/1/", folderAA.HidPath); folderTree = repository.GetFolderTree(rootFolder.Id); Console.WriteLine("Folder tree after reparent Folder AA to Folder B with Hid reorder: "); Console.Write(ToJson(folderTree)); Console.WriteLine(); Console.WriteLine(); // commit transaction tran.Commit(); }); } // !!!!! SEE CONSOLE OUTPUT !!!!!!!! }
public void TransactionTest() { var user1 = CreateNewUser(); user1 = _repository.SaveUser(user1); var id = user1.Id; _repository.BeginTransaction(tran => { //_repository.ExecuteCommand(cmd => //{ // cmd.UseSql($"delete from Users where Id = {id}"); //}); _repository.Execute("delete from Users where Id = @Id", cmd => cmd.AddIntParam("@Id", id)); //tran.Rollback(); }); user1 = _repository.GetUserById(user1.Id); Assert.IsNotNull(user1); Assert.AreEqual(user1.Id, id); var user2 = CreateNewUser(); user2 = _repository.SaveUser(user2); var id2 = user2.Id; _repository.BeginTransaction(tran => { _repository.ExecuteCommand(cmd => { cmd.UseSql($"delete from Users where Id = {id}"); }); _repository.DeleteUser(id2); tran.Rollback(); }); user1 = _repository.GetUserById(user1.Id); Assert.IsNotNull(user1); Assert.AreEqual(user1.Id, id); user2 = _repository.GetUserById(user2.Id); Assert.IsNotNull(user2); Assert.AreEqual(user2.Id, id2); _repository.DeleteTwoUsers(user1.Id, user2.Id); user1 = _repository.GetUserById(user1.Id); Assert.IsNull(user1); user2 = _repository.GetUserById(user2.Id); Assert.IsNull(user2); }
public void Transactions_are_not_rolled_back_if_already_rolled_back_from_exception_during_execution_of_a_SQL_statement() { var myBlog = new Blog("My blog"); var post1 = new BlogPost("Title 1", "Content 1 goes here"); using (var repository = new Repository()) { try { using (var transaction = repository.BeginTransaction()) { repository.Insert(myBlog); // Will throw exception due to foreign key constraints not being met repository.Insert(post1); transaction.Commit(); } } catch { // Swallow the exception } var actualBlog = repository.Find<Blog>().Where(x => x.Name == "My blog").Execute(); Assert.IsNull(actualBlog); } }
public void BeginTransaction(string newRefId = null) { Repository.BeginTransaction(newRefId); }