We have a query for about 40 data fields related to customers. The query will often return a large amount of records, say up to 20,000. We only want to use say around the first 500 results. Then, we just want to be able to page through them 10 at a time.
Is LINQ skip and take a reasonable approach for this? Are there any potentnialy performa开发者_C百科nce issues with using this approach vs doing it manually some other way?
Take()
without Skip()
generates SQL using TOP
clause.
Take()
with Skip
generates SQL using ROW_NUMBER()
as shown here.
Also, I'd recommend to use excellent LINQPad tool or LINQ to SQL logging to check generated queries.
Yes, if you're on SQL Server 2005+ it'll generate SQL that uses the ROW_NUMBER()
function to make paging efficient (not unlike the SQL that Scott uses in this blog post).
精彩评论