Ejemplo n.º 1
0
        public void TestSave() {
            var config = BuildSessionFactory();
            var sessionFactory = config.BuildSessionFactory();

            using (var session = sessionFactory.OpenSession()) {

                var user1 = new User { Name = "User 1" };
                session.Save(user1);
                //session.Flush();

                var user2 = new User { Name = "User 2" };
                session.Save(user2);
                //session.Flush();

                var role1 = new Role { Name = "Role 1" };
                session.Save(role1);
                var role2 = new Role { Name = "Role 2" };
                session.Save(role2);

                user1.Roles.Add(role1);
                user1.Roles.Add(role2);
                session.Update(user1);

                user2.Roles.Add(role1);
                user2.Roles.Add(role2);
                session.Update(user2);

                session.Flush();
            }
        }
Ejemplo n.º 2
0
        public void TestUpdate() {
            var config = BuildSessionFactory();
            var sessionFactory = config.BuildSessionFactory();

            using (var session = sessionFactory.OpenSession()) {
                var user = session.Query<User>().First();

                var firstRole = user.Roles.First();
                user.Roles.Remove(firstRole);
                session.Update(user);

                var roleCount = session.Query<Role>().Count();
                var role = new Role { Name = "Role " + (roleCount + 1) };
                session.Save(role);

                user.Roles.Add(role);
                session.Update(user);

                session.Update(user);
                session.Flush();
            }
        }