实体框架性能调整 [英] Entity framework performance tuning

查看:77
本文介绍了实体框架性能调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用实体框架来查询SQL Server数据库。 LINQ表达式是IQueryable。该查询大约需要10秒钟才能执行。如果这是在存储过程中,则我将处理查询以使其更有效。但是,如果我使用的是IQueryable,那么实体框架本身是否会决定如何构建有效的查询,还是我必须尝试使用​​linq表达式并通过反复试验来提高性能?

We are using entity framework to query a SQL server database. The LINQ expression is IQueryable. This query takes about 10 seconds to execute. If this were in a stored procedure, I would play around with the query to make it more efficient. However if I am using IQueryable, does entity framework itself decide on how to build an efficient query or do I have to play around with the linq expression and improve performance with trial and error?

推荐答案


实体框架本身是否决定如何构建有效的查询

does entity framework itself decide on how to build an efficient query

EF始终会自动确定如何构建查询,而sql -server也会自动优化查询。

EF will always automatically determine how to build the query, and sql -server also optimizes queries automagically.


我是否必须使用linq表达式并通过反复试验来提高性能?

do I have to play around with the linq expression and improve performance with trial and error?

您可以尝试使用查询,但通常较小的更改不会影响性能(就表达式的顺序而言)

You can try to play with the queries but typically minor changes won't affect performance (in terms of ordering of expressions)

您始终可以使用 SQL事件探查器来观察EF的作用并查看查询的效率。如果需要很长时间,则可以在SSMS中重新运行查询,然后打开包括实际执行计划并确定查询缓慢的地方。

You can always use SQL Profiler to watch what EF does and see how efficient the query is. If it takes you long you can rerun the query in SSMS and turn on Include Actual Execution Plan and determine where the query is slow.

这篇关于实体框架性能调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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