Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public virtual IEnumerable<TEntity> Get(int? page, Expression<Func<TEntity,bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
        {
            IQueryable<TEntity> query = dbSet;
            if (filter != null)
            {
                query = query.Where(filter);
            }

            foreach (var includeProperty in includeProperties.Split
                (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                query = query.Include(includeProperty);
            }

            if (orderBy != null)
            {
                return orderBy(query).ToPagedList(page ?? 1, 5);
                
            }
            else
            {
                
                return query.ToPagedList(page ?? 1, 5);
            }

        }


What I have tried:

I'm using generic repository and pagedlist.mvc.
Posted
Updated 11-Jun-18 4:29am

By supplying a non null value for
orderBy 


So say your list was of Person object


public class Person
{
   int Age{ get; set; }
}



I would try calling the repo code as follows

...Get(page: 1, filter: x => x.Age > 5, orderBy: people => people.OrderBy(x => x.Age), includeProperties: "");
 
Share this answer
 
v4
Comments
Zwe Hein 11-Jun-18 11:34am    
solved. I modified based on your suggestion. Thanks.

Get(orderBy: p => p.OrderBy(s => s.ProductID) )
Sacha Barber 11-Jun-18 11:46am    
Cool
I would have a look at the
ToPagedList()
that looks like some sort of extension method
 
Share this answer
 
Comments
Zwe Hein 11-Jun-18 10:07am    
yes. To use PageList function, must be sort. But I'm using generic repository. i need to sort but i don't know how to sort before PageList.

Thanks for your review.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900