public ActionResult ViewCategories(int id, int[] categories)
        {
            var product = _session.Get <Product>(id);

            // update categories
            if (Request.HttpMethod == "POST")
            {
                categories = categories ?? new int[0];
                using (var transaction = _session.BeginTransaction())
                {
                    var newCategories = categories.Length > 0 ?
                                        _session.Query <Category>().Where(c => categories.Contains(c.Id)) : (IEnumerable <Category>) new Category[0];

                    product.SetNewCategories(newCategories);

                    _session.SaveOrUpdate(product);
                    transaction.Commit();
                }
            }

            var model = new ProductsViewCategoriesViewModel();

            model.ProductCategories = product.Categories;

            // query categories prefetching children 3 levels deep
            model.Categories = _session.Query <Category>().Where(c => c.ParentCategory == null)
                               .FetchMany(c => c.ChildCategories)
                               .ThenFetchMany(c => c.ChildCategories)
                               .ThenFetchMany(c => c.ChildCategories);

            return(PartialView(model));
        }
        public ActionResult ViewCategories(int id, int[] categories)
        {
            var product = _session.Get<Product>(id);

            // update categories
            if (Request.HttpMethod == "POST")
            {
                categories = categories ?? new int[0];
                using (var transaction = _session.BeginTransaction())
                {
                    var newCategories = categories.Length > 0 ?
                        _session.Query<Category>().Where(c => categories.Contains(c.Id)) : (IEnumerable<Category>)new Category[0];

                    product.SetNewCategories(newCategories);

                    _session.SaveOrUpdate(product);
                    transaction.Commit();
                }
            }

            var model = new ProductsViewCategoriesViewModel();

            model.ProductCategories = product.Categories;

            // query categories prefetching children 3 levels deep
            model.Categories = _session.Query<Category>().Where(c => c.ParentCategory == null)
                .FetchMany(c => c.ChildCategories)
                .ThenFetchMany(c => c.ChildCategories)
                .ThenFetchMany(c => c.ChildCategories);

            return PartialView(model);
        }