开发者

Linq to SQL - Returning two values with one query

Is it possible to return a single value and an enumerable collection using LINQ to SQL?

The problem is, I'm trying to do paging across a large recordset. I only want to return 10 rows at a time so I'm using .Skip(20).Take(10) approach.

However I need to know the total number of records so I can show an appropriate page x of y.

T开发者_运维问答rying to avoid two separate queries.

Thanks


Don't be afraid of queries. Do both.


I came across this exact same issue and ended up with

var q = from i in tableName select i;

int total = q.Count();

foreach(var obj in q.Skip(20).Take(10))
{
    ...
}

It really wasn't a problem at all

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜