【发布时间】:2011-07-23 22:05:09
【问题描述】:
我正在我的 GridView 中实现分页。来自this的文章,我需要两个方法:
public IQueryable BindEmployees(int startRowIndex, int maximumRows)
{
EmployeeInfoDataContext dbEmp = new EmployeeInfoDataContext();
var query = from emp in dbEmp.Employees
join dept in dbEmp.Departments
on emp.DeptID equals dept.DeptID
select new
{
EmpID = emp.EmpID,
EmpName = emp.EmpName,
Age = emp.Age,
Address = emp.Address,
DeptName = dept.DepartmentName
};
return query.Skip(startRowIndex).Take(maximumRows);
}
和
public int GetEmployeeCount()
{
// How can I not repeat the logic above to get the count?
}
如何从第一种方法BindEmployees 中获取第二种方法GetEmployeeCount 的值?我的意思是不重复逻辑(查询)?
【问题讨论】:
-
你不能将返回的 IQueryable 转换为列表并进行计数吗?
.ToList().count应该给你计数。 -
为你投票,拉姆·艾耶。谢谢。
标签: c# asp.net linq iqueryable