Exemple #1
0
        public void SortByClauseListOptionsTest()
        {
            var options = new ListOptions()
            {
                Sort = "code-"
            };
            var list = options.GetSortings().ToArray();

            Assert.Single(list);
            Assert.Equal("code", list[0].Path);
            Assert.Equal(options.Sort, list[0].ToString());
        }
        /// <summary>
        /// Edits the sql query by adding meta-filtering based on the parameters and their ability to be filtered
        /// </summary>
        /// <typeparam name="TFilterable">The filterable entity</typeparam>
        /// <param name="sql">The sql to be modified</param>
        /// <param name="parameters">The named parameters to use as searchable fields</param>
        /// <param name="options">The <see cref="ListOptions"/> to add to the final SQL query</param>
        protected string AttachQueryOptions <TFilterable>(ref string sql, DynamicParameters parameters, ListOptions options)
            where TFilterable : class
        {
            if (options == null)
            {
                var defaultOptions = new ListOptions();

                QueryBuilder.AttachPagingOption(ref sql, defaultOptions.Page, defaultOptions.Size);
                QueryBuilder.AttachSizeOption(ref sql, defaultOptions.Size);

                return(sql);
            }

            AttachSearchOptions <TFilterable>(ref sql, options.Search, parameters);
            AttachSortOptions <TFilterable>(ref sql, options.GetSortings());
            QueryBuilder.AttachPagingOption(ref sql, options.Page, options.Size);
            QueryBuilder.AttachSizeOption(ref sql, options.Size);

            return(sql);
        }