public static CatalogNodeCollection LoadForCategory(Int32 categoryId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + CatalogNode.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_CatalogNodes");
            selectQuery.Append(" WHERE CategoryId = @categoryId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@categoryId", System.Data.DbType.Int32, categoryId);
            //EXECUTE THE COMMAND
            CatalogNodeCollection results = new CatalogNodeCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        CatalogNode catalogNode = new CatalogNode();
                        CatalogNode.LoadDataReader(catalogNode, dr);
                        results.Add(catalogNode);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        /// <summary>
        /// Gets the children for a given category.
        /// </summary>
        /// <param name="categoryId">Category to get children for</param>
        /// <param name="level">Level of the specified category</param>
        /// <param name="exclude">ID of the category to exclude from the collection; 0 if none.</param>
        /// <param name="publicOnly">If true, only include public categories in result set.</param>
        /// <returns></returns>
        private static CategoryLevelNodeCollection GetCategoryLevels(int categoryId, int level, int exclude, bool publicOnly)
        {
            CategoryLevelNodeCollection results      = new CategoryLevelNodeCollection();
            CatalogNodeCollection       catalogNodes = CatalogDataSource.Search(categoryId, string.Empty, true, publicOnly, false, CatalogNodeTypeFlags.Category);

            foreach (CatalogNode node in catalogNodes)
            {
                if (node.CatalogNodeId != exclude)
                {
                    CategoryLevelNode levelNode = new CategoryLevelNode();
                    levelNode.CategoryId    = node.CatalogNodeId;
                    levelNode.CategoryLevel = level;
                    levelNode.Name          = node.Name;
                    levelNode.ParentId      = categoryId;
                    results.Add(levelNode);
                    results.AddRange(GetCategoryLevels(levelNode.CategoryId, level + 1, exclude, publicOnly));
                }
            }
            return(results);
        }