我有以下Linq查询.它运作良好,但似乎令人困惑的是如何在linq中工作skip()
和take()
功能.这是我的查询
(from GRD in _tblAcademicYears.GetQueryable() where GRD.SchoolID == intSchoolID select new AcademicYearsModel { AcademicYearID = GRD.AcademicYearID, SchoolID = GRD.SchoolID, AcademicYearName = GRD.AcademicYearName, AcademicYearStart = GRD.AcademicYearStart, AcademicYearEnd = GRD.AcademicYearEnd, AcademicYearRemarks = GRD.AcademicYearRemarks, IsActive = GRD.IsActive, CreatedOn = GRD.CreatedOn, CreatedBy = GRD.CreatedBy, ModifiedOn = GRD.ModifiedOn, ModifiedBy = GRD.ModifiedBy } ).Where(z => z.AcademicYearName.Contains(param.sSearch) || z.AcademicYearStart.ToString().Contains(param.sSearch) || z.AcademicYearEnd.ToString().Contains(param.sSearch) || z.AcademicYearRemarks.Contains(param.sSearch)) .Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
此查询如何从数据库获取记录.它会从数据库中获取所有记录,然后将应用skip()
和take()
.或者它只是让拍摄与在限制skip()
和take()
当你打电话时.仅限它,它只会转换为SQL:TOP N语法
当您调用.Skip和.一起使用时,它将生成至少2个查询,方法是使用ROWNUMBER过滤掉.
所以你的问题的简短答案是:不,它不会从数据库中获取所有记录.它将运行一个SQL来过滤和选择.
如果您很好奇,可以始终使用SQL事件探查器或只是在调试模式下检查生成的SQL.
这是一篇简单的MSDN文章解释它 https://msdn.microsoft.com/library/bb386988(v=vs.100).aspx