LINQ到实体跳过()和Take() [英] Linq to Entities Skip() and Take()
问题描述
我工作的一个ASP.NET应用程序,我创建一个LINQ查询将从数据库中选择分页记录。用户界面上我有一个列表框,其中用户可以选择多种选择。我想知道:
-
我怎样才能增加跳过(),以()的参数来查看下一个结果?
-
我怎么可以用IN的关键字,这样如果用户在列表框中选择多个选项,查询可以查询所有值?
我的查询是这样的:
VAR的SearchResult = context.data_vault.Where(D => d.STATE == lstStates.SelectedItem.Text).OrderBy(D => d.dv_id)。取( 10).Skip(2);
GridView1.DataSource =的SearchResult;
GridView1.DataBind();
我想你使用的是跳过不正确。它应该是在起飞前。
跳过跳过了多项纪录,所以您的第一页,传递0,否则传中(页码 - 1)*每页记录。
我平时做这样的事情:
INT页= 1;
INT RecordsPerPage = 10;
变种Q = yourQuery.Skip((页 - 1)* RecordsPerPage)。取(RecordsPerPage);
I am working on an ASP.NET application and I am creating a LINQ query which will select paginated records from db. on user interface I have a listbox where user can select multiple choices. I want to know:
How can I increment Skip(), Take() parameters to view next results ?
How can I use "IN" key word so that if user selects multiple options from listbox, query can check all values ?
My query looks like this:
var searchResults = context.data_vault.Where(d => d.STATE == lstStates.SelectedItem.Text).OrderBy(d= > d.dv_id).Take(10).Skip(2);
GridView1.DataSource = searchResults;
GridView1.DataBind();
I think you are using Skip incorrectly. It should be before the Take.
Skip skips a number of records, so for your first page, pass in 0, else pass in the (page number - 1) * records per page.
I usually do something like this:
int Page = 1;
int RecordsPerPage = 10;
var q = yourQuery.Skip((Page - 1) * RecordsPerPage).Take(RecordsPerPage);
这篇关于LINQ到实体跳过()和Take()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!