public List <Role> SelectAllRoles(bool pSelectDeletedRoles) { string q = @"SELECT [Roles].[id], [code], [deleted], [description] FROM [Roles] WHERE 1 = 1 "; if (!pSelectDeletedRoles) { q += " AND [deleted] = 0"; } List <Role> Roles = new List <Role>(); using (SqlConnection conn = GetConnection()) { using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { using (OpenCbsReader r = c.ExecuteReader()) { if (r != null) { if (!r.Empty) { while (r.Read()) { Roles.Add(GetRole(r)); } } } } } } foreach (Role r in Roles) { r.SetMenuItems(GetAllowedMenuList(r.Id)); r.SetActionItems(GetAllowedActionList(r.Id)); } return(Roles); }