开发者

Linq to sql take skip and overall count

开发者 https://www.devze.com 2023-02-18 21:09 出处:网络
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.

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消