我已经在存储过程中完成了分页排序。但是现在,我需要在 LINQ 中对以下对象执行相同的操作。在以下场景中实现排序和分页的最易读的 LINQ 查询是什么?
代码
static List<Employee> GetMyData(int pageIndex, int pageSize, out int itemCount, string sortField, string sortDirection )
{
Employee e1= new Employee(){EmpID = 1, EmpName = "E1"};
Employee e2= new Employee(){EmpID = 2, EmpName = "E2"};
Employee e3= new Employee(){EmpID = 3, EmpName = "E3"};
Employee e4= new Employee(){EmpID = 4, EmpName = "E4"};
Employee e5= new Employee(){EmpID = 5, EmpName = "E5"};
Employee e6= new Employee(){EmpID = 6, EmpName = "E6"};
List<Employee> employees = new List<Employee>();
employees.Add(e1);
employees.Add(e2);
employees.Add(e3);
employees.Add(e4);
employees.Add(e5);
employees.Add(e6);
itemCount = employees.Count;
//Get subset of employees based on paging and sorting parameters
//Sorting can be based on EmpID or EmpName
List<Employee> currentPageEmployees = null;
return currentPageEmployees;
}
调用方法
int count = 0;
List<Employee> e = GetMyData(0, 2, out count, "EmpID", "descending");