コード例 #1
0
        public static int CalculateTotalCount <T>(this ObjectQuery <T> query, ISearchDataWrapper searchData)
        {
            int         ret = 0;
            ObjectQuery qry = query.Build(EntitySQLQueryWrapper.BuildEntitySQLQueryWrapper(searchData), true);

            if (qry is ObjectQuery <T> )
            {
                ret = ((ObjectQuery <T>)qry).Count();
            }
            else
            {
                ret = ((ObjectQuery <DbDataRecord>)qry).Count();
            }

            return(ret);
        }
コード例 #2
0
        public static EntitySQLQueryWrapper BuildEntitySQLQueryWrapper(SearchCriteriaBase criteria, PagingInfo pagingInfo, SortSequenceBase sortSequence)
        {
            EntitySQLQueryWrapper ret = new EntitySQLQueryWrapper();

            if (criteria != null)
            {
                ret.FillFromSearchCriteria(criteria);
            }
            if (sortSequence != null)
            {
                ret.FillFromSortSequence(sortSequence);
            }
            if (pagingInfo != null)
            {
                ret.FillFromPagingInfo(pagingInfo);
            }

            return(ret);
        }
コード例 #3
0
        internal void FillQuerySorts(List <EntitySQLSortItem> sorts, EntitySQLQueryWrapper wrapper)
        {
            IDictionary <EntitySQLFieldNameWithAggregation, int> items = this.PrepareItemsBeforeFilling(wrapper);

            if (items != null)
            {
                foreach (KeyValuePair <EntitySQLFieldNameWithAggregation, int> item in items.OrderBy(x => Math.Abs(x.Value)))
                {
                    if (item.Value > 0)
                    {
                        sorts.Add(new EntitySQLSortItem(item.Key.Name, item.Key.AggregationPattern, EntitySQLSortDirection.Ascending));
                    }
                    if (item.Value < 0)
                    {
                        sorts.Add(new EntitySQLSortItem(item.Key.Name, item.Key.AggregationPattern, EntitySQLSortDirection.Descending));
                    }
                }
            }
        }
コード例 #4
0
        private static ObjectQuery Build <T>(this ObjectQuery <T> query, EntitySQLQueryWrapper items, bool forTotalCount)
        {
            ObjectQuery     ret         = null;
            ObjectQuery <T> resultQuery = query;

            if (items != null)
            {
                string filters = items.BuildFilterSegment(resultQuery.Name);
                if (!String.IsNullOrEmpty(filters))
                {
                    resultQuery = resultQuery.Where(filters);
                }

                if (items.HasGroup)
                {
                    string groupProjection;
                    string groupKey = items.BuildGroupSegment(resultQuery.Name, out groupProjection);
                    ObjectQuery <DbDataRecord> interQuery = resultQuery.GroupBy(groupKey, groupProjection);
                    if (forTotalCount)
                    {
                        ret = interQuery;
                    }
                    else
                    {
                        interQuery  = interQuery.BuildSort(items, true);
                        interQuery  = interQuery.Select(items.GroupBy.BuildEntitySQLSegment(interQuery.Name));
                        resultQuery = query.Join(interQuery, items.GroupBy.FieldName);
                    }
                }
                else if (forTotalCount)
                {
                    ret = resultQuery;
                }
                if (!forTotalCount)
                {
                    ret = resultQuery.BuildSort(items, !items.HasGroup);
                }
            }

            return(ret);
        }
コード例 #5
0
        private static ObjectQuery <T> BuildSort <T>(this ObjectQuery <T> query, EntitySQLQueryWrapper items, bool plusPaging)
        {
            ObjectQuery <T> ret   = query;
            string          sorts = items.BuildSortSegment(ret.Name);

            if (!String.IsNullOrEmpty(sorts))
            {
                if (plusPaging && (items.StartIndex.GetValueOrDefault() > 0))
                {
                    ret = ret.Skip(sorts, items.StartIndex.ToString());
                }
                else
                {
                    ret = ret.OrderBy(sorts);
                }
            }
            if (plusPaging && items.Count.HasValue)
            {
                ret = ret.Top(items.Count.ToString());
            }

            return(ret);
        }
コード例 #6
0
 internal protected virtual void FillQueryFilters(List <EntitySQLFilterItem> filters, EntitySQLQueryWrapper wrapper)
 {
 }
コード例 #7
0
 public static ObjectQuery <T> BuildForResult <T>(this ObjectQuery <T> query, ISearchDataWrapper searchData)
 {
     return((ObjectQuery <T>)query.Build(EntitySQLQueryWrapper.BuildEntitySQLQueryWrapper(searchData), false));
 }
コード例 #8
0
 protected virtual void AddDefaultItems(IDictionary <EntitySQLFieldNameWithAggregation, int> items, EntitySQLQueryWrapper wrapper)
 {
 }
コード例 #9
0
        protected virtual IDictionary <EntitySQLFieldNameWithAggregation, int> PrepareItemsBeforeFilling(EntitySQLQueryWrapper wrapper)
        {
            IDictionary <EntitySQLFieldNameWithAggregation, int> ret = new Dictionary <EntitySQLFieldNameWithAggregation, int>(this.Items);

            if (ret.Count <= 0)
            {
                this.AddDefaultItems(ret, wrapper);
            }

            return(ret);
        }