Пример #1
0
        public static DataSourceResult ToCustomDataSourceResul(this IQueryable <OrderDetailViewModel> source, DataSourceRequest request)
        {
            var watch = Stopwatch.StartNew();

            //DataSourceResult result = AppliquerGroupePaginationAlternative(source, request);
            //========================== AppliquerGroupePaginationAlternative

            var grouping = request.ConvertirGroupeEnTri(source);
            var page     = request.Page;
            var pageSize = request.PageSize;

            //Remove the grouping before exeecuting the query against NHibernate

            request.Page     = 0;
            request.PageSize = 0;

            var total  = source.Count();
            var result = source.ToDataSourceResult(request);


            var skip = page > 0 ? (page - 1) * pageSize : 0;

            result.Data = result.Data.AsQueryable().Skip(skip).Take(pageSize);

            //Réappliquer le grouping
            request.Groups = grouping;
            result         = result.Data.ToDataSourceResult(request);
            result.Total   = total;


            //==========================

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Debug.WriteLine("============================================================");
            Debug.WriteLine("CustomDataSourceResult: " + elapsedMs + " ms");
            Debug.WriteLine("============================================================");

            return(result);
        }