コード例 #1
0
ファイル: PList.cs プロジェクト: bappidatta/ScopoMFinance
        /// <summary>
        /// Extension method converts the IEnumerable to a PList
        /// </summary>
        /// <typeparam name="T"> generic type </typeparam>
        /// <param name="theEnumerable">the enumerable</param>
        /// <param name="pager"> optionally, pass in a PagerSettings object in order to persist the values</param>
        /// <returns> new PList&#60;T&#62; </returns>
        public static PList <T> ToPList <T>(this IEnumerable <T> theEnumerable, PagerSettings pager = null)
        {
            PList <T> temp_ = new PList <T>();

            temp_.AddRange(theEnumerable);

            // use the provided pager settings
            temp_.Pager = pager == null ? new PagerSettings() : new PagerSettings(pager);

            return(temp_);
        }
コード例 #2
0
ファイル: PList.cs プロジェクト: bappidatta/ScopoMFinance
        /// <summary>
        /// Extension method applies paging to the current IQueryable instance and returns it
        /// without executing the query (it only executes a SELECT COUNT (1))
        /// </summary>
        /// <typeparam name="T"> ENTITY data type </typeparam>
        /// <param name="query"> query instance </param>
        /// <param name="pageNumber"> page index </param>
        /// <param name="pageSize"> page size </param>
        /// <param name="psettings"> out parameter will also contain the total number of records for the query </param>
        /// <remarks>
        /// This will trigger a proper SELECT COUNT(1) based on the current query IF this
        /// IQueryable instance was never converted to IEnumerable</remarks>
        /// <returns> query instance </returns>
        public static IQueryable <T> Page <T>(this IQueryable <T> query, int pageNumber, int pageSize, out PagerSettings psettings)
        {
            // This will trigger a proper SELECT COUNT(1) based on the current query IF this
            // IQueryable instance was never converted to IEnumerable
            int totalRecords = query.Count();

            psettings = new PagerSettings
            {
                TotalRecords = totalRecords,
                CurrentPage  = pageNumber,
                PageSize     = pageSize
            };

            return(query.Skip(pageNumber * pageSize).Take(pageSize));
        }