不要按属性排序

  • 本文关键字:排序 属性 c# linq
  • 更新时间 :
  • 英文 :


我有DB,由2个表组成:

**Job**
     job_id (int, primary key),
     job_nm (nchar(50))
**Employee**
     empl_id (int, primary key)
     job_id (int, forein key) (one-to-many)
     first_name (nchar(50))
     last_name (nchar(50))
     salary (float)

我按页输出表(每页5行)。它意识到:

ViewBag.Tab = (from employee in db.Employees 
               join job in db.Jobs on employee.job_id equals job.job_id 
               where job.job_nm == sel1 
               orderby employee.salary 
               select employee
              ).Skip(pageSize * pageNum)
               .Take(pageSize)
               .ToList();

但是我没有按"薪水"字段排序。

我试过这个代码:

ViewBag.Tab = (from employee in db.Employees 
               join job in db.Jobs 
               on employee.job_id equals job.job_id 
               where job.job_nm == sel1 
               orderby employee.salary 
               select employee
              ).Skip(pageSize * pageNum)
               .Take(pageSize)
               .ToList()
               .OrderBy(s => s.salary);

但没有结果。

我做错了什么?

OrderBy需要在SkipTake之前。否则,你就只能对你的小结果集进行排序。

试题:

ViewBag.Tab = (from employee in db.Employees 
               join job in db.Jobs 
               on employee.job_id equals job.job_id 
               where job.job_nm == sel1 
               orderby employee.salary 
               select employee
              ).OrderBy(s => s.salary)
               .Skip(pageSize * pageNum)
               .Take(pageSize)
               .ToList();

相关内容

  • 没有找到相关文章

最新更新