public void UpdateHomeCategorySet(int rowNumber, IEnumerable <long> categoryIds)
        {
            if (rowNumber > 14 || rowNumber < 0)
            {
                throw new ArgumentNullException(string.Concat("行号不在取值范围内!取值必须大于0且小于", 14));
            }
            CategoryService categoryService = new CategoryService();
            int             num             = categoryIds.Count();

            HomeCategoryInfo[] homeCategoryInfoArray = new HomeCategoryInfo[num];
            for (int i = 0; i < num; i++)
            {
                long             num1             = categoryIds.ElementAt <long>(i);
                HomeCategoryInfo homeCategoryInfo = new HomeCategoryInfo()
                {
                    RowNumber  = rowNumber,
                    CategoryId = num1,
                    Depth      = categoryService.GetCategory(num1).Depth
                };
                homeCategoryInfoArray[i] = homeCategoryInfo;
            }
            context.HomeCategoryInfo.OrderBy((HomeCategoryInfo item) => item.RowNumber == rowNumber);
            context.HomeCategoryInfo.AddRange(homeCategoryInfoArray);
            context.SaveChanges();
        }
        public void UpdateHomeCategorySet(int rowNumber, IEnumerable <long> categoryIds)
        {
            if (rowNumber > HOME_CATEGORY_SET_COUNT || rowNumber < 0)
            {
                throw new ArgumentNullException("行号不在取值范围内!取值必须大于0且小于" + HOME_CATEGORY_SET_COUNT);
            }

            var  categoryService = new CategoryService();
            var  categoriesCount = categoryIds.Count();
            var  homeCategories  = new HomeCategoryInfo[categoriesCount];
            long categoryId;

            for (var i = 0; i < categoriesCount; i++)
            {
                categoryId        = categoryIds.ElementAt(i);
                homeCategories[i] = new HomeCategoryInfo()
                {
                    RowNumber  = rowNumber,
                    CategoryId = categoryId,
                    Depth      = categoryService.GetCategory(categoryId).Depth
                };
            }
            Context.HomeCategoryInfo.Remove(item => item.RowNumber == rowNumber);//移除原所有首页分类
            Context.HomeCategoryInfo.AddRange(homeCategories);
            Context.SaveChanges();
        }
        public void UpdateHomeCategorySet(int rowNumber, IEnumerable <long> categoryIds)           //程序有问题
        {
            if (rowNumber > 14 || rowNumber < 0)
            {
                throw new ArgumentNullException(string.Concat("行号不在取值范围内!取值必须大于0且小于", 14));
            }
            CategoryService categoryService = new CategoryService();
            int             num             = categoryIds.Count();

            HomeCategoryInfo[] homeCategoryInfoArray = new HomeCategoryInfo[num];
            for (int i = 0; i < num; i++)
            {
                long             num1             = categoryIds.ElementAt <long>(i);
                HomeCategoryInfo homeCategoryInfo = new HomeCategoryInfo()
                {
                    RowNumber  = rowNumber,
                    CategoryId = num1,
                    Depth      = categoryService.GetCategory(num1).Depth
                };

                homeCategoryInfoArray[i] = homeCategoryInfo;
            }
            //需要先判断数据库中是否已存在,而不能直接添加
            //   context.HomeCategoryInfo.OrderBy((HomeCategoryInfo item) => item.RowNumber == rowNumber);
            context.HomeCategoryInfo.Remove((HomeCategoryInfo item) => item.RowNumber == rowNumber);

            /*int cn = 0;                            //记录需要存储的记录数;
             * Boolean[] sp = new Boolean[num];
             * for (int i = 0; i < num; i++)
             * {
             *  sp[i] = true;
             *  int k = (int)homeCategoryInfoArray[i].CategoryId;
             *  int m= context.HomeCategoryInfo.Where(item => item.CategoryId == k).Count();
             * // int m = ddddd.ToList().Count();
             *  if (m == 0)
             *  {
             *      cn++;
             *      sp[i] = false;
             *  }
             * }
             * HomeCategoryInfo[] NewArray = new HomeCategoryInfo[cn];
             * int cm = 0;
             * for (int i = 0; i < num;i++ )
             * {
             *  if (!sp[i])
             *  {
             *      NewArray[cm] = homeCategoryInfoArray[i];
             *      cm++;
             *  }
             * }*/
            // context.HomeCategoryInfo.AddRange(NewArray);

            //context.HomeCategoryInfo.
            context.HomeCategoryInfo.AddRange(homeCategoryInfoArray);
            context.SaveChanges();
            //  context.SaveChanges();
        }