public object[] getTeacherList(Teacher teacher, int rows, int page)
        {
            object[]  result  = new object[2];
            ISession  session = getSession();
            ICriteria c       = session.CreateCriteria(typeof(Teacher));

            if (!string.IsNullOrEmpty(teacher.Name))
            {
                c.Add(Restrictions.Like("Name", teacher.Name, MatchMode.Anywhere));
            }
            if (!string.IsNullOrEmpty(teacher.Sex))
            {
                c.Add(Restrictions.Eq("Sex", teacher.Sex));
            }
            if (!string.IsNullOrEmpty(teacher.Sn))
            {
                c.Add(Restrictions.Eq("Sn", teacher.Sn));
            }
            if (!string.IsNullOrEmpty(teacher.IDcode))
            {
                c.Add(Restrictions.Like("IDcode", teacher.IDcode, MatchMode.Anywhere));
            }
            ICriteria c2 = (ICriteria)c.Clone();

            result[0] = getCount(c2);
            page      = page > 0 ? page : 1;
            c.SetFirstResult((page - 1) * rows);
            c.SetMaxResults(rows);
            result[1] = c.List <Teacher>();
            return(result);
        }
예제 #2
0
        public IEnumerable <T> FindAllByCriteria(List <ICriterion> critorions, out int TotalRecord, int index, int count, string sort, string dir)
        {
            ICriteria criteriaQuery = SessionFactory.Instance.GetCurrentSession().CreateCriteria(typeof(T));

            if (critorions != null)
            {
                foreach (var crit in critorions)
                {
                    criteriaQuery.Add(crit);
                }
            }
            TotalRecord = (int)((ICriteria)criteriaQuery.Clone()).SetProjection(Projections.RowCount()).UniqueResult();
            if (sort != null && sort.Length > 2)
            {
                criteriaQuery.AddOrder(new Order(sort, dir.ToLower() == "asc" ? true : false));
            }
            criteriaQuery.SetFirstResult(index);
            if (count > 0)
            {
                criteriaQuery.SetMaxResults(count);
            }
            List <T> Datas = (List <T>)criteriaQuery.List <T>();

            foreach (T Data in Datas)
            {
                if (Data != null)
                {
                    Data.Bersih();
                }
            }
            return(Datas);
        }
예제 #3
0
        public QueryResult Result <T>(string queryString)
        {
            var       hasInline  = HasInlineCount(queryString);
            ICriteria query      = Criteria <T>(queryString);
            ICriteria countQuery = (ICriteria)query.Clone();

            var list = query.Future <T>();

            QueryResult result;

            if (hasInline)
            {
                countQuery.ClearOrders();
                var count = countQuery
                            .SetFirstResult(0)
                            .SetMaxResults(Int32.MaxValue)
                            .SetProjection(Projections.RowCount()).FutureValue <Int32>();

                result = new QueryResult()
                {
                    InlineCount = count.Value, Results = list
                };
            }
            else
            {
                result = new QueryResult()
                {
                    Results = list
                };
            }
            return(result);
        }
예제 #4
0
        private ICriteria Clone(ICriteria criteria)
        {
            ICriteria criteriaClone = criteria.Clone() as ICriteria;

            criteriaClone.ClearOrders();

            return(criteriaClone);
        }
예제 #5
0
        /// <summary>
        /// Gets the count of entities.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns>The entity count.</returns>
        public virtual long Count(ICriteria criteria)
        {
            var countCriteria = (ICriteria)criteria.Clone();

            countCriteria.SetProjection(Projections.RowCount());
            long count;

            Int64.TryParse(countCriteria.List()[0].ToString(), out count);

            return(count);
        }
예제 #6
0
        //DetachedCriteria
        public IEnumerable <T> Fetch(Framework.Common.NHibernate.CriterionRequest <T> Criterion)
        {
            ICriteria criterias = this.Session.CreateCriteria <T>();

            if (Criterion.Criterias != null)
            {
                foreach (var exp in Criterion.Criterias)
                {
                    criterias.Add(exp.Compile().Invoke());
                }
            }
            if (Criterion.Associations != null)
            {
                foreach (var aexp in Criterion.Associations)
                {
                    criterias.CreateCriteria(aexp.AssociationPath, aexp.Alias);
                    if (aexp.Criterias != null)
                    {
                        foreach (var child in aexp.Criterias)
                        {
                            criterias.Add(child.Compile().Invoke());
                        }
                    }
                }
            }
            ICriteria totalcriteria = criterias.Clone() as ICriteria;

            Criterion.Totals = totalcriteria.SetProjection(Projections.RowCount()).UniqueResult <int>();
            if (Criterion.Orders != null)
            {
                foreach (var order in Criterion.Orders)
                {
                    criterias.AddOrder(order.Compile().Invoke());
                }
            }
            if (Criterion.Associations != null)
            {
                foreach (var aexp in Criterion.Associations)
                {
                    if (aexp.Orders != null)
                    {
                        foreach (var child in aexp.Orders)
                        {
                            criterias.AddOrder(child.Compile().Invoke());
                        }
                    }
                }
            }
            criterias.SetFirstResult((Criterion.CurrentPage - 1) * Criterion.PageSize)
            .SetMaxResults(Criterion.PageSize);
            Criterion.DataList = criterias.List <T>();
            return(Criterion.DataList);
        }
예제 #7
0
 private void CloneProjectCrtieria(CriteriaImpl clone)
 {
     if (projectionCriteria != null)
     {
         if (projectionCriteria == this)
         {
             clone.projectionCriteria = clone;
         }
         else
         {
             ICriteria clonedProjectionCriteria = (ICriteria)projectionCriteria.Clone();
             clone.projectionCriteria = clonedProjectionCriteria;
         }
     }
 }
예제 #8
0
        /// <summary>
        /// 获取用户分页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="name"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public IList <ls_user> GetPagedUserList(int pageIndex, int pageSize, string name, string startTime, string endTime, int role_id, out int totalCount)
        {
            //ICriteria criteria = db.CreateCriteria(typeof(ls_user));
            //Disjunction dis = Restrictions.Disjunction();
            //if (!string.IsNullOrEmpty(name))
            //{
            //    dis.Add(Restrictions.Like("user_name","%"+name+"%"));
            //}
            //if (!string.IsNullOrEmpty(startTime))
            //{
            //    dis.Add(Restrictions.Gt("create_time",Convert.ToDateTime(startTime)));
            //}
            //if (!string.IsNullOrEmpty(endTime))
            //{
            //    dis.Add(Restrictions.Lt("create_time", Convert.ToDateTime(endTime)));
            //}
            //criteria.Add(dis);
            //totalCount=(int)criteria.SetProjection(Projections.RowCount()).UniqueResult();
            //criteria.SetFirstResult(pageIndex*pageSize);
            //criteria.SetMaxResults(pageSize);
            //return criteria.List<ls_user>();
            ICriteria criteria = db.CreateCriteria(typeof(ls_user), "t1");

            if (!string.IsNullOrEmpty(name))
            {
                criteria.Add(Restrictions.Like("user_name", "%" + name + "%"));
            }
            if (!string.IsNullOrEmpty(startTime))
            {
                criteria.Add(Restrictions.Gt("create_time", Convert.ToDateTime(startTime)));
            }
            if (!string.IsNullOrEmpty(endTime))
            {
                criteria.Add(Restrictions.Lt("create_time", Convert.ToDateTime(endTime)));
            }
            if (role_id > 0)
            {
                criteria.CreateAlias("user_roles", "t2");
                criteria.Add(Restrictions.Eq("t2.id", role_id));
            }
            ICriteria totalCriteria = (ICriteria)criteria.Clone();

            totalCount = (int)totalCriteria.SetProjection(Projections.RowCount()).UniqueResult();
            criteria.AddOrder(Order.Desc("id"));
            criteria.SetFirstResult((pageIndex - 1) * pageSize);
            criteria.SetMaxResults(pageSize);
            return(criteria.List <ls_user>());
        }
        public object[] searchPlan(IList professionList, string YearNo, string LevelNo, int rows, int page)
        {
            using (ISession session = getSession())
            {
                object[]  result = new object[2];
                ICriteria ic     = session.CreateCriteria(typeof(ExamPlan));
                ic.CreateCriteria("Profession");
                if (professionList != null && professionList.Count > 0)
                {
                    Object[] professionArr = new object[professionList.Count];
                    for (int i = 0; i < professionList.Count; i++)
                    {
                        professionArr[i] = professionList[i];
                    }
                    ic.Add(Restrictions.In("Profession", professionArr));
                }
                if (!string.IsNullOrEmpty(YearNo))
                {
                    ic.Add(Restrictions.Eq("YearNo", YearNo + ""));
                }

                if (!string.IsNullOrEmpty(LevelNo))
                {
                    ic.Add(Restrictions.Eq("LevelNo", LevelNo));
                }
                ICriteria ic2 = (ICriteria)ic.Clone();
                result[0] = getCount(ic2);

                page = page > 0 ? page : 1;
                ic.SetFirstResult((page - 1) * rows);
                ic.SetMaxResults(rows);
                IList <ExamPlan> planList = ic.List <ExamPlan>();
                foreach (ExamPlan p in planList)
                {
                    p.ProfessionName = p.Profession.Name;
                    p.FacultyName    = p.Faculty.Name;
                    p.CouresCount    = Convert.ToString(p.CouresSet.Count);
                    p.BeginTimeStr   = p.BeginTime.ToString("yyyy-MM-dd");
                }
                result[1] = planList;

                return(result);
            }
        }
예제 #10
0
        public IEnumerable <T> FindAll(int index, int pageSize, out int count)
        {
            ICriteria CriteriaQuery = _uow.Session.CreateCriteria(typeof(T));

            index = (index >= 1?index:1);


            var countCirteria = CriteriaQuery.Clone() as ICriteria;

            var futureCount = countCirteria.SetProjection(Projections.RowCount()).FutureValue <Int32>();

            count = futureCount.Value;

            var queryList = CriteriaQuery.SetFirstResult((index - 1) * pageSize).SetMaxResults(pageSize).List();



            return((List <T>)queryList);
        }
예제 #11
0
        public object[] searchCoures(IList professionList, string YearNo, string LevelNo, int rows, int page)
        {
            using (ISession session = getSession())
            {
                object[]  result = new object[2];
                ICriteria ic     = session.CreateCriteria(typeof(Coures));
                ic.CreateCriteria("Profession");
                if (professionList != null && professionList.Count > 0)
                {
                    Object[] professionArr = new object[professionList.Count];
                    for (int i = 0; i < professionList.Count; i++)
                    {
                        professionArr[i] = professionList[i];
                    }
                    ic.Add(Restrictions.In("Profession", professionArr));
                }
                if (!string.IsNullOrEmpty(YearNo))
                {
                    ic.Add(Restrictions.Eq("YearNo", YearNo + ""));
                }

                if (!string.IsNullOrEmpty(LevelNo))
                {
                    ic.Add(Restrictions.Eq("LevelNo", LevelNo));
                }
                ICriteria ic2 = (ICriteria)ic.Clone();
                result[0] = getCount(ic2);

                rows = rows == 0 ? 100 : rows;
                page = page > 0 ? page : 1;
                ic.SetFirstResult((page - 1) * rows);
                ic.SetMaxResults(rows);
                IList <Coures> couresList = ic.List <Coures>();
                foreach (Coures c in couresList)
                {
                    c.ProfessionName = c.Profession.Name;
                }
                result[1] = couresList;

                return(result);
            }
        }
예제 #12
0
        public IPageOfList <T> GetByExample(T exampleInstance, int pageIndex, int pageSize, params string[] propertiesToExclude)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);
            Example   example  = Example.Create(exampleInstance);

            foreach (string propertyToExclude in propertiesToExclude)
            {
                example.ExcludeProperty(propertyToExclude);
            }
            example.ExcludeNone();
            example.ExcludeNulls();
            example.ExcludeZeroes();

            int recordTotal = Convert.ToInt32((criteria.Clone() as ICriteria).SetProjection(Projections.Count("ID")).UniqueResult());

            criteria.AddOrder(new Order("ID", false));
            criteria.Add(example).SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize);

            return(new PageOfList <T>(criteria.List <T>(), pageIndex, pageSize, recordTotal));
        }
예제 #13
0
        public static PagedList <T> PagedList <T>(this ICriteria criteria, ISession session, int pageIndex, int pageSize) where T : class
        {
            if (pageIndex < 0)
            {
                pageIndex = 0;
            }

            var countCrit = (ICriteria)criteria.Clone();

            countCrit.ClearOrders(); // so we don't have missing group by exceptions

            var results = session.CreateMultiCriteria()
                          .Add <long>(countCrit.SetProjection(Projections.RowCountInt64()))
                          .Add <T>(criteria.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize))
                          .List();

            var totalCount = ((IList <long>)results[0])[0];

            return(new PagedList <T>((IList <T>)results[1], totalCount, pageIndex, pageSize));
        }
        public object[] getStudentList(Student student, int rows, int page)
        {
            object[]  result  = new object[2];
            ISession  session = getSession();
            ICriteria c       = session.CreateCriteria(typeof(Student));

            if (!string.IsNullOrEmpty(student.Name))
            {
                c.Add(Restrictions.Like("Name", student.Name, MatchMode.Anywhere));
            }
            if (!string.IsNullOrEmpty(student.Sex))
            {
                c.Add(Restrictions.Eq("Sex", student.Sex));
            }
            if (!string.IsNullOrEmpty(student.IDcode))
            {
                c.Add(Restrictions.Like("IDcode", student.IDcode, MatchMode.Anywhere));
            }
            if (!string.IsNullOrEmpty(student.Sn))
            {
                c.Add(Restrictions.Like("Sn", student.Sn, MatchMode.Anywhere));
            }
            if (student.ProfessionList != null && student.ProfessionList.Count > 0)
            {
                c.Add(Restrictions.In("Profession", student.ProfessionList.ToArray()));
            }
            ICriteria c2 = (ICriteria)c.Clone();

            result[0] = getCount(c2);
            page      = page > 0 ? page : 1;
            c.SetFirstResult((page - 1) * rows);
            c.SetMaxResults(rows);
            IList <Student> studentList = c.List <Student>();

            foreach (Student s in studentList)
            {
                s.ProfessionName = s.Profession.Name;
            }
            result[1] = studentList;
            return(result);
        }
        public Page <TResult> Page(short pNumber, short pSize, SortType pSort, params Expression <Func <TResult, object> >[] pOrderBy)
        {
            var _count = ((ICriteria)_query.Clone()).SetProjection(Projections.Count(Projections.Id())).FutureValue <Int32>();

            for (short f = 0; f < pOrderBy.GetLength(0); f++)
            {
                if (pSort == SortType.Ascending)
                {
                    string _name = (pOrderBy[f].Body as UnaryExpression) != null ? (((pOrderBy[f].Body as UnaryExpression).Operand as System.Linq.Expressions.MemberExpression).Member.Name) : (pOrderBy[f].Body as MemberExpression).Member.Name;
                    _query = _query.AddOrder(new Order(_name, true));
                }
                else
                {
                    string _name = (pOrderBy[f].Body as UnaryExpression) != null ? (((pOrderBy[f].Body as UnaryExpression).Operand as System.Linq.Expressions.MemberExpression).Member.Name) : (pOrderBy[f].Body as MemberExpression).Member.Name;
                    _query = _query.AddOrder(new Order(_name, false));
                }
            }
            IEnumerable <TResult> _result = _query.SetMaxResults(pSize).SetFirstResult((pNumber - 1) * pSize).List <TResult>();

            return(new Page <TResult>(pNumber, pSize, _count.Value, _result));
        }
예제 #16
0
        /// <summary>
        /// ICriteria 对象的分页查询
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public virtual Page <TEntity> GetList <TEntity>(ICriteria query, int pageIndex, int pageSize)
        {
            //query.SetLockMode(LockMode.None);
            var countCriteria = (query.Clone() as ICriteria).SetProjection(Projections.Count(Projections.Id())).SetMaxResults(1);

            countCriteria.ClearOrders();

            var pageCriteria = query.SetFirstResult((pageIndex - 1) * pageSize).SetMaxResults(pageSize);

            var multiQuery = Session.CreateMultiCriteria().Add <int>("count", countCriteria).Add <TEntity>("page", pageCriteria);

            var result = new Page <TEntity> {
                Paging = new Paging {
                    PageIndex = pageIndex, PageSize = pageSize
                }
            };

            result.Records      = ((IList <TEntity>)multiQuery.GetResult("page")).ToList();
            result.Paging.Total = ((IList <int>)multiQuery.GetResult("count")).Single();
            //result.Records.ForEach(x => { Session.Evict(x); });
            return(result);
        }
예제 #17
0
        public IEnumerable <T> FindAllByCriteriaQuery(ICriteria criteriaQuery, out int TotalRecord, int index, int count, string sort, string dir)
        {
            TotalRecord = (int)((ICriteria)criteriaQuery.Clone()).SetProjection(Projections.RowCount()).UniqueResult();
            if (sort != null && sort.Length > 2)
            {
                criteriaQuery.AddOrder(new Order(sort, dir.ToLower() == "asc" ? true : false));
            }
            criteriaQuery.SetFirstResult(index);
            if (count > 0)
            {
                criteriaQuery.SetMaxResults(count);
            }
            List <T> Datas = (List <T>)criteriaQuery.List <T>();

            foreach (T Data in Datas)
            {
                if (Data != null)
                {
                    Data.Bersih();
                }
            }
            return(Datas);
        }
예제 #18
0
        private PagedResult <Employee> GetPagedResultForQuery(ISession session, ICriteria criteria, int page, int pageSize)
        {
            var countCriteria = ((ICriteria)criteria.Clone()).SetProjection(Projections.CountDistinct <Employee>(x => x.Id));

            criteria.SetResultTransformer(new DistinctRootEntityResultTransformer()).SetMaxResults(pageSize).SetFirstResult((page - 1) * pageSize);
            criteria.AddOrder(Order.Asc("Name"));
            var multi = session.CreateMultiCriteria()
                        .Add(countCriteria)
                        .Add(criteria)
                        .List();

            var result = new PagedResult <Employee>();

            result.CurrentPage = page;
            result.PageSize    = pageSize;
            result.RowCount    = (int)((IList)multi[0])[0];
            var pageCount = (double)result.RowCount / result.PageSize;

            result.PageCount = (int)Math.Ceiling(pageCount);

            result.Results = ((IList)multi[1]).Cast <Employee>().ToList();
            return(result);
        }
예제 #19
0
        public PagedList <DemoArticle> GetArticleByTags(IEnumerable <Tag> tags, ArticleCriteria cr)
        {
            using (var session = sessionFactory.OpenSession())
            {
                ICriteria filter = session.CreateCriteria(typeof(Article));
                if (cr.LastId > 0)
                {
                    filter.Add(Restrictions.Lt("Id", cr.LastId));
                }

                else
                {
                    filter.SetFirstResult(cr.StartFrom);
                }
                filter.CreateAlias("Tags", "tag");
                filter.Add(Expression.In("tag.Id", tags.Select(m => m.Id).ToArray()));
                //criteria.SetProjection(Projections.Distinct(Projections.Property("Id")));

                var result        = new PagedList <DemoArticle>();
                var countCreteria = (ICriteria)filter.Clone();
                result.AddRange(
                    filter
                    .SetProjection(Projections.Distinct(Projections.ProjectionList()
                                                        .Add(Projections.Id(), "Id")
                                                        .Add(Projections.Property("Title"), "Title")
                                                        .Add(Projections.Property("Image"), "Image")
                                                        .Add(Projections.Property("ShortDescription"), "ShortDescription")
                                                        .Add(Projections.Property("CreateDate"), "CreateDate")
                                                        .Add(Projections.Property("LastUpdateDate"), "LastUpdateDate")))
                    .AddOrder(Order.Desc("Id"))
                    .SetResultTransformer(Transformers.AliasToBean <DemoArticle>())
                    .List <DemoArticle>());
                result.LinesCount = countCreteria.SetProjection(Projections.RowCount()).UniqueResult <int>();
                result.PageCount  = (int)Math.Ceiling(result.LinesCount / (double)cr.Count);
                return(result);
            }
        }
        public object[] searchExamResult(IList <ExamPlan> examPlanList, int rows, int page)
        {
            using (ISession session = getSession())
            {
                object[]  result = new object[2];
                ICriteria ic     = session.CreateCriteria(typeof(ExamResult));
                ic.Add(Restrictions.In("ExamPlan", examPlanList.ToArray()));
                ICriteria ic2 = (ICriteria)ic.Clone();
                result[0] = getCount(ic2);

                page = page > 0 ? page : 1;
                ic.SetFirstResult((page - 1) * rows);
                ic.SetMaxResults(rows);
                IList <ExamResult> examResultList = ic.List <ExamResult>();
                foreach (ExamResult er in examResultList)
                {
                    er.ExamPlanName = er.ExamPlan.Name;
                    er.StudentName  = er.Student.Name;
                    er.StudentSN    = er.Student.Sn;
                }
                result[1] = examResultList;
                return(result);
            }
        }
예제 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryList"></param>
        /// <param name="order"></param>
        /// <param name="index"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IEnumerable <T> FindBy(IList <ICriterion> queryList, Order order, int index, int pageSize, out int count)
        {
            ICriteria CriteriaQuery = _uow.Session.CreateCriteria(typeof(T));

            foreach (var queryItem in queryList)
            {
                CriteriaQuery.Add(queryItem);
            }

            var listByQuery = CriteriaQuery;


            var countCrieriaQuery = CriteriaQuery.Clone() as ICriteria;

            //            // Get the total row count in the database.
            //var rowCount = this.Session.CreateCriteria(typeof(EventLogEntry))
            //    .Add(Expression.Between("Timestamp", startDate, endDate))
            //    .SetProjection(Projections.RowCount()).FutureValue<Int32>();

            //// Get the actual log entries, respecting the paging.
            //var results = this.Session.CreateCriteria(typeof(EventLogEntry))
            //    .Add(Expression.Between("Timestamp", startDate, endDate))
            //    .SetFirstResult(pageIndex * pageSize)
            //    .SetMaxResults(pageSize)
            //    .Future<EventLogEntry>();



            var rowCount = countCrieriaQuery.SetProjection(Projections.RowCount()).FutureValue <Int32>();

            count = rowCount.Value;

            index = index >= 1 ? index : 1;

            return(listByQuery.AddOrder(order).SetFirstResult((index - 1) * pageSize).SetMaxResults(pageSize).List <T>());
        }
예제 #22
0
        ��������private void CloneProjectCrtieria(CriteriaImpl clone)
        ��������
        {
            ������������if(projectionCriteria != null)
            ������������ {
                ����������������if(projectionCriteria == this)
                ���������������� {
                    ��������������������clone.projectionCriteria = clone;
                    ����������������
                }
                ����������������else
                ���������������� {
                    ��������������������ICriteria clonedProjectionCriteria = (ICriteria)projectionCriteria.Clone();

                    ��������������������clone.projectionCriteria = clonedProjectionCriteria;
                    ����������������
                }
                ������������
            }
            ��������
        }
예제 #23
0
 ///<summary>
 /// Returns a clone of the original criteria, which will return the count
 /// of rows that are returned by the original criteria query.
 ///</summary>
 public static ICriteria TransformToRowCount(ICriteria criteria)
 {
     return(TransformToRowCount((CriteriaImpl)criteria.Clone()));
 }
예제 #24
0
 /// <summary>
 /// Creates an exact clone of the criteria
 /// </summary>
 /// <returns></returns>
 public static ICriteria Clone(ICriteria criteria)
 {
     return((CriteriaImpl)criteria.Clone());
 }
예제 #25
0
		/// <summary>
		/// Creates an exact clone of the criteria
		/// </summary>
		/// <returns></returns>
		public static ICriteria Clone(ICriteria criteria)
		{
			return (CriteriaImpl) criteria.Clone();
		}
예제 #26
0
		///<summary>
		/// Returns a clone of the original criteria, which will return the count 
		/// of rows that are returned by the original criteria query.
		///</summary>
		public static ICriteria TransformToRowCount(ICriteria criteria)
		{
			return TransformToRowCount((CriteriaImpl)criteria.Clone());
		}
        /// <summary>
        /// Prepare list of used images
        /// Many be associated with products, as thumbnail, icon, or std. images
        /// or as additional images
        /// or to option swathces
        /// </summary>
        private void InitAssociatedImageUrls()
        {
            associatedImages = new List <string>();

            // ADD PRODUCT IMAGES
            ICriteria criteria = NHibernateHelper.CreateCriteria <Product>();

            criteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            criteria.Add(Restrictions.Disjunction()
                         .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("IconUrl", "~/Assets/ProductImages/%")));

            IList <Product> products = ProductDataSource.LoadForCriteria(criteria);

            foreach (Product product in products)
            {
                if (product.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.ImageUrl);
                }
                if (product.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.ThumbnailUrl);
                }
                if (product.IconUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.IconUrl);
                }
            }

            // ADDITIONAL IMAGES
            ICriteria imageCriteria = NHibernateHelper.CreateCriteria <ProductImage>();

            imageCriteria.Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"));
            IList <ProductImage> images = ProductImageDataSource.LoadForCriteria(imageCriteria);

            foreach (ProductImage image in images)
            {
                associatedImages.Add(image.ImageUrl);
            }

            // OPTION SWATCHES
            ICriteria choicesCriteria = NHibernateHelper.CreateCriteria <OptionChoice>();

            choicesCriteria.Add(Restrictions.Disjunction()
                                .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                                .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%")));

            IList <OptionChoice> choices = OptionChoiceDataSource.LoadForCriteria(choicesCriteria);

            foreach (OptionChoice choice in choices)
            {
                if (choice.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(choice.ImageUrl);
                }
                if (choice.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(choice.ThumbnailUrl);
                }
            }

            // ADD CATEGORY IMAGES
            ICriteria categoryCriteria = NHibernateHelper.CreateCriteria <Category>();

            categoryCriteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            categoryCriteria.Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"));
            IList <Category> categories = CategoryDataSource.LoadForCriteria(categoryCriteria);

            foreach (Category category in categories)
            {
                if (category.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(category.ThumbnailUrl);
                }
            }

            // ADD LINK IMAGES
            ICriteria linksCriteria = NHibernateHelper.CreateCriteria <Link>();

            linksCriteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            linksCriteria.Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"));
            IList <Link> links = LinkDataSource.LoadForCriteria(linksCriteria);

            foreach (Link link in links)
            {
                if (link.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(link.ThumbnailUrl);
                }
            }

            // ADD GIFT WRAPING IMAGES
            ICriteria wrapstylesCriteria = NHibernateHelper.CreateCriteria <WrapStyle>();

            wrapstylesCriteria.Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"));

            IList <WrapStyle> wrapStyles = WrapStyleDataSource.LoadForCriteria(wrapstylesCriteria);

            foreach (WrapStyle ws in wrapStyles)
            {
                if (ws.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(ws.ImageUrl);
                }
                if (ws.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(ws.ThumbnailUrl);
                }
            }

            // ADD VARIANT IMAGES
            ICriteria variantsCriteria = NHibernateHelper.CreateCriteria <ProductVariant>();

            criteria.Add(Restrictions.Disjunction()
                         .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("IconUrl", "~/Assets/ProductImages/%")));

            int variantsCount      = ProductVariantDataSource.CountForCriteria(variantsCriteria.Clone() as ICriteria);
            int maxVariantsToCache = 500;

            // avoid loading all variants at same time
            for (int index = 0; index < variantsCount; index += maxVariantsToCache)
            {
                variantsCriteria.SetMaxResults(maxVariantsToCache);
                variantsCriteria.SetFirstResult(index);
                IList <ProductVariant> productVariants = ProductVariantDataSource.LoadForCriteria(variantsCriteria);
                foreach (ProductVariant productVariant in productVariants)
                {
                    if (productVariant.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.ImageUrl);
                    }
                    if (productVariant.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.ThumbnailUrl);
                    }
                    if (productVariant.IconUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.IconUrl);
                    }
                }
            }
        }