public IEnumerable<Role> GetAllRoles(string @namespace, int? pageIndex = null, int? pageSize = null)
		{
			var entity = new RoleEntity();
			var dataAccess = this.EnsureService<IDataAccess>();

			var oql = OQL.From(entity)
						 .Select()
						 .Where(p => p.Compare(entity.Namespace, "=", Utility.TrimNamespace(@namespace)))
						 .OrderBy(p => p.Desc(entity.RoleId))
						 .End();

			if(pageIndex != null && pageSize != null)
				oql.Limit(pageSize.Value, pageIndex.Value);

			var entities = dataAccess.Select<RoleEntity>(oql);

			return Mapper.Map<IEnumerable<RoleEntity>, IEnumerable<Role>>(entities);
		}
		public Role GetRole(int roleId)
		{
			var entity = new RoleEntity();
			var dataAccess = this.EnsureService<IDataAccess>();
			var oql = OQL.From(entity).Select().Where(p => p.Property(entity.RoleId) == roleId).End();

			entity = dataAccess.Find<RoleEntity>(oql);

			return Mapper.Map<RoleEntity, Role>(entity);
		}
		public IEnumerable<Role> GetRoles(int memberId, MemberType memberType)
		{
			var role = new RoleEntity();
			var member = new MemberEntity();
			var dataAccess = this.EnsureService<IDataAccess>();

			var child = OQL.From(member)
						   .Select(member.RoleId)
						   .Where(p => p.Compare(member.MemberId, "=", memberId) & p.Compare(member.MemberType, "=", Convert.ConvertValue<byte>(memberType)))
						   .End();

			var master = OQL.From(role)
							.Select()
							.Where(p => p.Compare(role.RoleId, CompareOperator.In, child))
							.End();

			var entities = dataAccess.Select<RoleEntity>(master);

			return Mapper.Map<IEnumerable<RoleEntity>, IEnumerable<Role>>(entities);
		}
		public void SetMembers(int roleId, IEnumerable<Member> members)
		{
			if(members == null)
				return;

			var dataAccess = this.EnsureService<IDataAccess>();

			foreach(var member in members)
			{
				member.RoleId = roleId;
			}

			var entity = new RoleEntity();

			dataAccess.BeginTransaction();

			try
			{
				// 清空指定角色的所有成员
				dataAccess.Execute(OQL.From(entity).Delete().Where(p => p.Compare(entity.RoleId, "=", roleId)).End());

				// 插入指定的角色成员集到数据库中
				this.CreateMembers(members);

				// 提交事物
				dataAccess.Commit();
			}
			catch(Exception ex)
			{
				dataAccess.Rollback();
	
				throw ex;
			}
		}
		public int DeleteRoles(params int[] roleIds)
		{
			if(roleIds == null || roleIds.Length < 1)
				return 0;

			var entity = new RoleEntity();
			var dataAccess = this.EnsureService<IDataAccess>();
			var oql = OQL.From(entity).Delete().Where(p => p.Compare(entity.RoleId, CompareOperator.In, roleIds)).End();

			return dataAccess.Execute(oql);
		}