public void Commit_And_Rollback_Work() { Person person = new Person { Id = Guid.NewGuid(), FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString() }; // Rollback using (DbSession dbSession = GetSession()) { IKeyedRepository<Guid, Person> repo = dbSession.CreateKeyedRepository<Guid, Person>(); repo.Add(person); dbSession.Rollback(); } using (DbSession dbSession = GetSession()) { IKeyedRepository<Guid, Person> repo = dbSession.CreateKeyedRepository<Guid, Person>(); Assert.IsNull(repo.FindBy(person.Id)); } // Commit using (DbSession dbSession = GetSession()) { IKeyedRepository<Guid, Person> repo = dbSession.CreateKeyedRepository<Guid, Person>(); repo.Add(person); dbSession.Commit(); } using (DbSession dbSession = GetSession()) { IKeyedRepository<Guid, Person> repo = dbSession.CreateKeyedRepository<Guid, Person>(); Assert.IsNotNull(repo.FindBy(person.Id)); } // Cleanup using (DbSession dbSession = GetSession()) { IKeyedRepository<Guid, Person> repo = dbSession.CreateKeyedRepository<Guid, Person>(); repo.Delete(person); dbSession.Commit(); } }
/// <summary> /// Create a new Person object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static Person CreatePerson(global::System.Guid id) { Person person = new Person(); person.Id = id; return person; }
/// <summary> /// Deprecated Method for adding a new object to the People EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPeople(Person person) { base.AddObject("People", person); }