LINQ通常比相等的SQL语句慢吗 [英] Is LINQ generally slower than a equal SQL statement

查看:155
本文介绍了LINQ通常比相等的SQL语句慢吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我写了一个带有许多group by子句的大型SQL语句,依此类推;使用普通的SQL(也许是存储过程)会更快吗,还是Linq仅将其解析为一个非常好的SQL语句并为我提供了相当快的结果?

If I write a large SQL statement with many group by clauses and so on; would it be much faster with normal SQL (maybe a stored procedure), or is Linq only parsing it to a very nice SQL statement and gives me my results quite fast?

推荐答案

在某些情况下,您 可能比LINQ to SQL更好地调整SQL ...但是LINQ实际上是 运行SQL.并不是将所有数据都提取到流程中,然后然后进行处理.您可以(并且应该)记录正在生成的SQL并分析任何看起来可疑的内容.

In some cases you may be able to tune the SQL better than LINQ to SQL... but LINQ really is running SQL. It's not fetching all the data into the process and then doing the processing. You can (and should) log what SQL is being generated and profile anything that looks suspicious.

当然,这是将查询转换为SQL开头的开销(这就是为什么您可以对其进行预编译的原因),然后还有将数据转换为对象并跟踪ID等的开销.以我的经验,这通常不是很大的开销.像以往一样,配置您的代码...

Of course, there's the overhead of converting the query into SQL to start with (which is why you're able to precompile them) and then there's the overhead of converting the data into objects - and keeping track of the IDs etc. In my experience this is usually not a significant overhead though. As ever, profile your code...

这篇关于LINQ通常比相等的SQL语句慢吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆