예제 #1
0
        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();
            }
        }
예제 #2
0
 /// <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;
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the People EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPeople(Person person)
 {
     base.AddObject("People", person);
 }