コード例 #1
0
 /// <summary>
 /// Asynchronously creates a <see cref="IPagedList{T}"/> from a <see cref="IEnumerable{T}"/>.
 /// Calling this method invokes executing the query and applying the filter defined by <see cref="DataTablesRequest{T}"/>.
 /// <param name="source"><see cref="IEnumerable{T}"/> to be filtered and paginated.</param>
 /// <param name="request"><see cref="DataTablesRequest{T}"/> instance with filtering parameters.</param>
 /// </summary>
 public static Task <IPagedList <T> > ToPagedListAsync <T>(this IEnumerable <T> source, DataTablesRequest <T> request)
 {
     return(Task.Factory.StartNew(() => source.AsQueryable().ToPagedList(request)));
 }
コード例 #2
0
 /// <summary>
 /// Asynchronously creates a <see cref="IPagedList{T}"/> from a <see cref="IQueryable{T}"/>.
 /// Calling this method invokes executing the query and applying the filter defined by <see cref="DataTablesRequest{T}"/>.
 /// </summary>
 /// <typeparam name="T">Data type</typeparam>
 /// <param name="queryable"><see cref="IQueryable{T}"/> to be filtered and paginated.</param>
 /// <param name="request"><see cref="DataTablesRequest{T}"/> instance with filtering parameters.</param>
 /// <returns><see cref="IPagedList{T}"/> intstance.</returns>
 public static Task <IPagedList <T> > ToPagedListAsync <T>(this IQueryable <T> queryable, DataTablesRequest <T> request)
 {
     return(Task.Factory.StartNew(() => queryable.Filter(request).ToPagedList()));
 }
コード例 #3
0
 /// <summary>
 /// Creates a <see cref="IPagedList{T}"/> from a <see cref="IEnumerable{T}"/>.
 /// Calling this method invokes executing the query and immediate applying the filter defined by <see cref="DataTablesRequest{T}"/>.
 /// <param name="source"><see cref="IEnumerable{T}"/> to be filtered and paginated immediately.</param>
 /// <param name="request"><see cref="DataTablesRequest{T}"/> instance with filtering parameters.</param>
 /// </summary>
 public static IPagedList <T> ToPagedList <T>(this IEnumerable <T> source, DataTablesRequest <T> request)
 {
     return(source.AsQueryable().ToPagedList(request));
 }
コード例 #4
0
 /// <summary>
 /// Creates a <see cref="IPagedList{T}"/> from a <see cref="IQueryable{T}"/>.
 /// Calling this method invokes executing the query and immediate applying the filter defined by <see cref="DataTablesRequest{T}"/>.
 /// </summary>
 /// <typeparam name="T">Data type</typeparam>
 /// <param name="queryable"><see cref="IQueryable{T}"/> to be filtered and paginated immediately.</param>
 /// <param name="request"><see cref="DataTablesRequest{T}"/> instance with filtering parameters.</param>
 /// <returns><see cref="IPagedList{T}"/> intstance.</returns>
 public static IPagedList <T> ToPagedList <T>(this IQueryable <T> queryable, DataTablesRequest <T> request)
 {
     return(queryable.Filter(request).ToPagedList());
 }
コード例 #5
0
 /// <summary>
 /// Converts the <see cref="IQueryable{T}"/> to <see cref="IDataTablesQueryable{T}"/>.
 /// </summary>
 /// <typeparam name="T"><see cref="IQueryable{T}"/> element type.</typeparam>
 /// <param name="queryable"><see cref="IQueryable{T}"/> instance to be converted to <see cref="IDataTablesQueryable{T}"/>.</param>
 /// <param name="request"><see cref="DataTablesRequest{T}"/> instance with request parameters.</param>
 /// <returns><see cref="IDataTablesQueryable{T}"/> instance.</returns>
 public static IDataTablesQueryable <T> AsDataTablesQueryable <T>(this IQueryable <T> queryable, DataTablesRequest <T> request)
 {
     return(new DataTablesQueryable <T>(queryable, request));
 }
コード例 #6
0
        /// <summary>
        /// Modifies the <see cref="IQueryable{T}"/> by applying <see cref="DataTablesRequest{T}"/> filtering parameters.
        /// </summary>
        /// <typeparam name="T">Data type to be filtered</typeparam>
        /// <param name="queryable"><see cref="IQueryable{T}"/> instance to be filtered.</param>
        /// <param name="request"><see cref="DataTablesRequest{T}"/> instance that stores filterning request parameters</param>
        /// <returns><see cref="IDataTablesQueryable{T}"/> with appied <see cref="DataTablesRequest{T}"/></returns>
        public static IDataTablesQueryable <T> Filter <T>(this IQueryable <T> queryable, DataTablesRequest <T> request)
        {
            // Modify the IQueryable<T> with consecutive steps.
            // If you need to change the order or add extra steps,
            // you should to write own Filter<T> extension method similarly.
            queryable =

                // convert IQueryable<T> to IDataTablesQueryable<T>
                queryable.AsDataTablesQueryable(request)

                // apply custom filter, if specified
                .CustomFilter()

                // perform global search by all searchable columns
                .GlobalSearch()

                // perform individual columns search by all searchable columns
                .ColumnsSearch()

                // order the IDataTablesQueryable<T> by columns listed in the request
                .Order();

            if (request.Log != null)
            {
                StringBuilder sb = new StringBuilder("DataTables.Queryable -> Incoming request:\n");
                foreach (string key in request.OriginalRequest.AllKeys)
                {
                    string value = request.OriginalRequest[key];
                    sb.AppendLine($"{key} = {$"\"{value}\""}");
                }
                sb.AppendLine();
                sb.AppendLine($"DataTables.Queryable -> Resulting queryable:\n{queryable}\n");

                request.Log.BeginInvoke(sb.ToString(), null, null);
            }

            return((IDataTablesQueryable <T>)queryable);
        }
コード例 #7
0
 internal DataTablesQueryProvider(IQueryProvider sourceProvider, DataTablesRequest <T> request)
 {
     this.sourceProvider = sourceProvider;
     this.request        = request;
 }
コード例 #8
0
 internal DataTablesQueryable(IQueryable <T> query, DataTablesRequest <T> request)
 {
     this.sourceQueryable = query;
     this.sourceProvider  = new DataTablesQueryProvider <T>(query.Provider, request);
     this.request         = request;
 }
コード例 #9
0
        /// <summary>
        /// Modifies the <see cref="IQueryable{T}"/> by applying <see cref="DataTablesRequest{T}"/> filtering parameters.
        /// </summary>
        /// <typeparam name="T">Data type to be filtered</typeparam>
        /// <param name="queryable"><see cref="IQueryable{T}"/> instance to be filtered.</param>
        /// <param name="request"><see cref="DataTablesRequest{T}"/> instance that stores filterning request parameters</param>
        /// <returns><see cref="IDataTablesQueryable{T}"/> with appied <see cref="DataTablesRequest{T}"/></returns>
        public static IDataTablesQueryable <T> Filter <T>(this IQueryable <T> queryable, DataTablesRequest <T> request)
        {
            // Modify the IQueryable<T> with consecutive steps.
            // If you need to change the order or add extra steps,
            // you should to write own Filter<T> extension method similarly.
            queryable =

                // convert IQueryable<T> to IDataTablesQueryable<T>
                queryable.AsDataTablesQueryable(request)

                // apply custom filter, if specified
                .CustomFilter()

                // perform global search by all searchable columns
                .GlobalSearch()

                // perform individual columns search by all searchable columns
                .ColumnsSearch()

                // order the IDataTablesQueryable<T> by columns listed in the request
                .Order();

#if TRACE
            Trace.WriteLine($"DataTables.Queryable resulting query:\n {queryable}");
#endif
            return((IDataTablesQueryable <T>)queryable);
        }