存储过程与EF代码优先的性能问题 [英] Performance Issue between Stored Procedure and EF Code First

查看:110
本文介绍了存储过程与EF代码优先的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想检索数据列表并首先使用EF代码显示它( < a href =http://msdn.microsoft.com/en-in/data/dn468673> http://msdn.microsoft.com/en-in/data/dn468673 [ ^ ])或存储过程( http:/ /msdn.microsoft.com/en-us/data/jj592907.aspx [ ^ ]),哪一个有最短的时间来检索它?

If I want to retrieve a list of data and display it by using EF code first (http://msdn.microsoft.com/en-in/data/dn468673[^]) or stored procedure (http://msdn.microsoft.com/en-us/data/jj592907.aspx[^]), which of them has the shortest time to retrieve it?

推荐答案

在不知道你的意图的情况下,我明白了,你试着比较那些不应该比较的东西。

可以说,EF Code First非常有效(参见: http://msdn.microsoft.co m / en-us / data / hh949853.aspx [ ^ ]),但远没有直接写入SQL查询那么高效。但是,如果你谈论存储过程,你可能不是简单地在存储过程中包装一个简单的查询 - 你会添加一些逻辑。此时,通过使用EF并在托管代码中运行该逻辑而不是在t-sql中使用花哨技巧,您可能会获益良多。但是你必须让层运行该逻辑尽可能接近数据存储区(在同一台机器上运行)。



如果你需要高级逻辑和大多数性能一样,您应该考虑使用CLR集成功能,例如 CLR存储过程 [ ^ ]。
Without knowing your intentions, as I see, you try to compare things that should not be compared.
One can say, EF Code First is quite efficient (see: http://msdn.microsoft.com/en-us/data/hh949853.aspx[^]), but far not as efficient as writting SQL query directly. Still, if you speak about stored procedure, you are probably not simply wrapping a simple query in a stored procedure - you would add some logic. At this point you might well gain by using EF and running that logic in managed code instead of using fancy trick in t-sql. But you have to have the tier running that logic as close to the datastore as you can get (running on the same machine).

Still, if you need advanced logic and most performance, you should consider making use of the CLR integrated features, like the CLR stored procedure[^].


这篇关于存储过程与EF代码优先的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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