简体   繁体   English

LINQ跳跳走有不错的表现吗?

[英]Does LINQ skip & take have decent performance?

We have a query for about 40 data fields related to customers. 我们查询约40个与客户相关的数据字段。 The query will often return a large amount of records, say up to 20,000. 该查询通常会返回大量记录,例如最多20,000。 We only want to use say around the first 500 results. 我们只想在前500个结果中使用说。 Then, we just want to be able to page through them 10 at a time. 然后,我们只希望能够一次翻阅10个页面。

Is LINQ skip and take a reasonable approach for this? LINQ是否跳过此步骤并采取合理的方法? Are there any potentnialy performance issues with using this approach vs doing it manually some other way? 与使用其他方式手动执行此方法相比,是否存在任何潜在的性能问题?

Take() without Skip() generates SQL using TOP clause. 没有Skip() Take()使用TOP子句生成SQL。

Take() with Skip generates SQL using ROW_NUMBER() as shown here . Take()Skip生成SQL使用ROW_NUMBER()如图所示这里

Also, I'd recommend to use excellent LINQPad tool or LINQ to SQL logging to check generated queries. 另外,我建议使用出色的LINQPad工具或LINQ to SQL日志记录来检查生成的查询。

是的,如果您使用的是SQL Server 2005+,它将生成使用ROW_NUMBER()函数提高分页效率的SQL(与Scott在此博客文章中使用的SQL不同)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM