Linq to sql take skip and overall count
Take a query
dim q = from i in db.test select i.name
Now I use count
to get the complete number of the items.
I use them to get a pager control:
dim count = q.count
Then I use take
and skip
to get my records.
This produces two queries and I wonder if there is a possibility to get the count of all items but to select only 10 of t开发者_StackOverflowhem so that l2s produces just one query.
The columns would then look like:
allcount
- name
This query would give me 10 items, but in the column allcount would be the complete number of all items.
try using 'new' statement; it always works for me :)
var _data = from i in db.test select new { count = i.name.count(), records = i.name };
You can also see my blog on basic LINQ to SQL queries: LinqtoSQL
Hope it helps!
精彩评论