Esempio n. 1
0
        public void Can_User_Add_And_Delete_Roles_In_A_Many_To_Many_bidirectional_Association()
        {
            UserWithManyToMany detachedUser = null;

            using (IUnitOfWork unitOfWork = new UnitOfWork())
            {
                detachedUser = new UserWithManyToMany { Name = "User" };
                unitOfWork.Session.Save(detachedUser);

                for (int i = 0; i < 5; i++)
                {
                    var role = new RoleWithManyToMany { Name = string.Format("Order: {0}", i) };
                    detachedUser.AddRole(role);
                }

                unitOfWork.Commit();
            }

            using (IUnitOfWork unitOfWork = new UnitOfWork())
            {
                var user = unitOfWork.Session.Query<UserWithManyToMany>().Fetch(x => x.Roles).Single(x => x.Id == detachedUser.Id);
                var role = user.Roles.ElementAt(0);
                user.RemoveRole(role);

                unitOfWork.Commit();
            }

            Assert.Equal(6, _sessionFactory.Statistics.EntityInsertCount);
        }
 public virtual void RemoveUser(UserWithManyToMany user)
 {
     Users.Remove(user);
     user.Roles.Remove(this);
 }
 public virtual void RemoveUser(UserWithManyToMany user)
 {
     Users.Remove(user);
     user.Roles.Remove(this);
 }
 public virtual void AddUser(UserWithManyToMany user)
 {
     Users.Add(user);
     user.Roles.Add(this);
 }
 public virtual void AddUser(UserWithManyToMany user)
 {
     Users.Add(user);
     user.Roles.Add(this);
 }