示例#1
0
        public static SqlKata.Query ApplySorting(this SqlKata.Query q, ISortedQuery opts, string timestampColumn,
                                                 string entityIdColumn)
        {
            if (opts.Order == SortOrder.Asc)
            {
                q.OrderBy(timestampColumn, entityIdColumn);
            }
            else
            {
                q.OrderByDesc(timestampColumn, entityIdColumn);
            }

            if (opts is IPaginatedQuery pq)
            {
                if (pq.Page != null)
                {
                    q.WhereRaw(opts.Order == SortOrder.Asc
                            ? $"({timestampColumn}, {entityIdColumn}) > (?, ?)"
                            : $"({timestampColumn}, {entityIdColumn}) < (?, ?)",
                               pq.Page.Timestamp, pq.Page.EntityId);
                }
            }

            if (opts.Count != null)
            {
                q.Limit(opts.Count.Value);
            }

            return(q);
        }
        private static void AddSortingToSqlBuilder(IDapperQuery <TResult> dapperQuery, ISortedQuery <TResult> sortedQuery)
        {
            var sqlBuilder = dapperQuery.SqlBuilder;

            foreach (var configuration in sortedQuery.SortingConfiguration !)
            {
                var sortDirection = configuration.GetSortDirection();
                var fieldName     = configuration.GetFieldName <TResult>() !;

                sqlBuilder.OrderBy($"{fieldName} {sortDirection}");
            }
        }
示例#3
0
 public IOrderedQueryable <T> ApplyQuery <T>(ISortedQuery <T> query) where T : UniqueEntity
 {
     return(query.GetSortingExpression()(Query <T>().Where(query.GetFilterExpression())));
 }