Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary> Create a query (ICriteria) </summary>
        public ICriteria CreateCountQuery(ICriteria criteria)
        {
            ICriteria criteriaClone = CriteriaTransformer.Clone(criteria);

            criteriaClone.ClearOrders();
            return(criteriaClone.SetFirstResult(0).SetProjection(Projections.RowCount()));
        }
Exemplo n.º 3
0
        /// <summary> Create a query (ICriteria) </summary>
        public ICriteria CreateCountQuery(DetachedCriteria detachedCriteria)
        {
            ICriteria executableCriteria = detachedCriteria.GetExecutableCriteria(_session);

            executableCriteria.ClearOrders();
            return(executableCriteria.SetFirstResult(0).SetProjection(Projections.RowCount()));
        }
Exemplo n.º 4
0
        protected virtual PagedList <T> FindPagedInternal(int pageIndex, int pageSize, Func <ICriteria, ICriteria> func)
        {
            ICriteria rowCountCriteria = func != null?func(CreateCriteria()) : CreateCriteria();

            rowCountCriteria.ClearOrders();
            IFutureValue <int> rowCount =
                rowCountCriteria
                .SetFirstResult(0)
                .SetMaxResults(RowSelection.NoValue)
                .SetProjection(Projections.RowCount())
                .FutureValue <int>();

            ICriteria pagingCriteria = func != null?func(CreateCriteria()) : CreateCriteria();

            IList <T> qryResult =
                pagingCriteria
                .SetFirstResult((pageIndex - 1) * pageSize)
                .SetMaxResults(pageSize)
                .Future <T>()
                .ToList <T>();

            PagedList <T> result = new PagedList <T>(qryResult, pageIndex, pageSize, rowCount.Value);

            return(result);
        }
Exemplo n.º 5
0
        private ICriteria Clone(ICriteria criteria)
        {
            ICriteria criteriaClone = criteria.Clone() as ICriteria;

            criteriaClone.ClearOrders();

            return(criteriaClone);
        }
 public ICriteria CreateOrderCriteria(ICriteria criteria)
 {
     if (!this.IsClientSort())
     {
         return(criteria);
     }
     if (this.Order.ToLower() == Asc)
     {
         criteria.ClearOrders();
         criteria.AddOrder(NHibernate.Criterion.Order.Asc(this.Sort));
     }
     else if (this.Order.ToLower() == Desc)
     {
         criteria.ClearOrders();
         criteria.AddOrder(NHibernate.Criterion.Order.Desc(this.Sort));
     }
     return(criteria);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Find by ICriteria created by client with Pagination and Sorting
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// This pagination signature is designed to work with ASP.NET ObjectDataSource, for more advanced pagination, please consider NHiberante.Burrow.Util.Pagination.IPaginator, NHiberante.Burrow.Util
        /// </remarks>
        protected IList <ReturnT> Find(int startRow, int pageSize, string sortExpression, ICriteria c)
        {
            Order o = ParseOrder(sortExpression);

            if (o != null)
            {
                c.ClearOrders();
                c.AddOrder(o);
            }
            return(Find(pageSize, startRow, c));
        }
        protected override LinqExpression VisitMethodCall(MethodCallExpression call)
        {
            switch (call.Method.Name)
            {
            case "First":
                results = HandleFirstCall(call);
                break;

            case "FirstOrDefault":
                results = HandleFirstOrDefaultCall(call);
                break;

            case "Single":
                results = HandleSingleCall(call);
                break;

            case "SingleOrDefault":
                results = HandleSingleOrDefaultCall(call);
                break;

            case "Aggregate":
                results = HandleAggregateCallback(call);
                break;

            case "Average":
            case "Count":
            case "LongCount":
            case "Max":
            case "Min":
            case "Sum":
                rootCriteria.ClearOrders();
                results = HandleAggregateCall(call);
                break;

            case "Any":
                results = HandleAnyCall(call);
                break;

            default:
                throw new NotImplementedException("The method " + call.Method.Name + " is not implemented.");
            }

            return(call);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Clear all orders from criteria.
 /// </summary>
 public void ClearOrders()
 {
     criteria.ClearOrders();
 }