locked
filterexpression RRS feed

  • Question

  • User-1651183775 posted

    Hello guys,

    I want to make amendment to below function to accommodate filter-expression and  not sure how to achieve it. can someone help me with this?

      public static IQueryable<T> PagedResult<T, TResult>(IQueryable<T> query, int pageNum, int pageSize,
                    Expression<Func<T, TResult>> orderByProperty, bool isAscendingOrder, string filterExpression, out int rowsCount)
            {
                //if (pageSize <= 0) pageSize = 20;
    
                //Total result count
                rowsCount = query.Count();
    
                //If page number should be > 0 else set to first page
                if (rowsCount <= pageSize || pageNum <= 0) pageNum = 1;
    
                //Calculate nunber of rows to skip on pagesize
                int excludedRows = (pageNum - 1) * pageSize;
    
                query = isAscendingOrder ? query.OrderBy(orderByProperty) : query.OrderByDescending(orderByProperty);  
    
    query= query.Where(????);         
    
                //Skip the required rows for the current page and take the next records of pagesize count
                return query.Skip(excludedRows).Take(pageSize);
            }


     

    Wednesday, January 31, 2018 12:14 PM

All replies

  • User-832373396 posted

    <g class="gr_ gr_261 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="261" data-gr-id="261">Hi</g> <g class="gr_ gr_262 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="262" data-gr-id="262">kodnil</g>,

    query= query.Where(????); 

    Sir, please change a bit to your current code;

    ep.

    add this Expression<Func<T, bool>> whereLambda) as parameter ;

    public static IQueryable<T> PagedResult<T, TResult>(IQueryable<T> query, int pageNum, int pageSize,Expression<Func<T, bool>> whereLambda,
                    Expression<Func<T, TResult>> orderByProperty, bool isAscendingOrder, string filterExpression, out int rowsCount)
            {
                //if (pageSize <= 0) pageSize = 20;
    
                //Total result count
                rowsCount = query.Count();
    
                //If page number should be > 0 else set to first page
                if (rowsCount <= pageSize || pageNum <= 0) pageNum = 1;
    
                //Calculate nunber of rows to skip on pagesize
                int excludedRows = (pageNum - 1) * pageSize;
    
                query = isAscendingOrder ? query.OrderBy(orderByProperty) : query.OrderByDescending(orderByProperty);  
    
    query= query.Where(whereLambda);         
    
                //Skip the required rows for the current page and take the next records of pagesize count
                return query.Skip(excludedRows).Take(pageSize);
            }

    2 and here is full example https://forums.asp.net/post/6182246.aspx 

    Welcome to back if any question :)

    With regards, Angelina Jolie

    Thursday, February 1, 2018 6:31 AM