LINQ 有多快?

时间:2023-02-03
本文介绍了LINQ 有多快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要处理 100,000 - 200,000 条记录.
我正在考虑使用 LINQ(到 SQL)来做到这一点.
我从经验中知道过滤数据视图非常慢.
那么 LINQ 有多快?

您能否告诉我您的经验以及它是否值得使用,或者我最好使用 SQL 存储过程(繁重且不那么灵活)?

在数千条记录中,我需要找到数据组然后对其进行处理,每组大约有 50 条记录.

I need to manipulate 100,000 - 200,000 records.
I am thinking of using LINQ (to SQL) to do this.
I know from experience that filtering dataviews is very slow.
So how quick is LINQ?

Can you please tell me your experiences and if it is worth using, or would I be better off using SQL stored procedures (heavy going and less flexible)?

Within the thousands of records I need to find groups of data and then process them, each group has about 50 records.

推荐答案

LINQ to SQL 将您的查询表达式转换为 T-SQL,因此您的查询性能应该与您通过 ADO.NET 发送该 SQL 查询完全相同.我猜想将查询的表达式树转换为等效的 T-SQL 会产生一些开销,但我的经验是,与实际查询时间相比,这很小.

LINQ to SQL translates your query expression into T-SQL, so your query performance should be exactly the same as if you sent that SQL query via ADO.NET. There is a little overhead I guess, to convert the expression tree for your query into the equivalent T-SQL, but my experience is that this is small compared with the actual query time.

您当然可以准确地找出生成的 T-SQL,因此请确保您有良好的支持索引.

You can of course find out exactly what T-SQL is generated, and therefore make sure you have good supporting indexes.

与 DataViews 的主要区别在于 LINQ to SQL 不会将所有数据放入内存并在那里对其进行过滤.相反,它让数据库做它擅长的事情,并且只将匹配的数据带入内存.

The primary difference from DataViews is that LINQ to SQL does not bring all the data into memory and filter it there. Rather it gets the database to do what it's good at and only brings the matching data into memory.

这篇关于LINQ 有多快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:实体框架 nvarchar 外键区分大小写 下一篇:Linq to sql 选择成一个新类

相关文章

最新文章