I use the following code to retrieve data for a gridview binding, but for performance issues I only want to get the selected datarows range, say 1-10 for the first page, 11-20 for the second page .... How can I make that change the following code
public IQueryable<Employee> SelectEmployees(string SortColumn, string SortOrder, long UserID,---int start,---int end)
{
IUnitOfWork objUow;
var arg = Expression.Parameter(typeof(Employee), "Employee");
var sortProperty = Expression.Property(arg, SortColumn);
var lambda = Expression.Lambda(sortProperty, arg);
var param = Expression.Parameter(typeof(IQueryable<Employee>));
var orderByCall = Expression.Call(typeof(Queryable), SortOrder, new Type[] { typeof(Employee), sortProperty.Type }, new Expression[] { param, lambda });
var orderLambda = Expression.Lambda<Func<IQueryable<Employee>, IQueryable<Employee>>>(orderByCall, param).Compile();
var Ids = objUow.Repository<Users>().Entities.Where((x => x.ID == UserID)).Select(y => y.Id);
return orderLambda(objUow.Repository<Employee>().Entities.Where(x => x.IsDeleted != true && x.Status == 1 && Ids.Contains(x.CheckID)));
}
I have Tried skip (). take (), but it solves the error ....
return orderLambda((objUow.Repository<Employee>().Entities.Where(x => x.IsDeleted != true && x.Status == 1 && Ids.Contains(x.CheckID))).Skip(0).Take(10));
An exception of type "System.NotSupportedException" occurred in EntityFramework.SqlServer.dll, but was not processed in the user code
Additional Information: The Skip method is only supported for sorted input in LINQ to Entities. The OrderBy method must be called before the Skip method.
-
IQueryable<Employee> Obj= orderLambda(objUow.Repository<Employee>().Entities.Where(x => x.IsDeleted != true && x.InvalidStatus == 1 && shopids.Contains(x.CheckID)));
Obj.Skip(0).Take(10);