实体框架与ADO.NET [英] Entity Framework vs. ADO.NET

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

问题描述

在ASP.NET MVC3项目,是更快,更安全,使用实体框架(与存储库模式),或者使用ADO.NET与的SqlConnection 的SqlCommand

In ASP.NET MVC3 projects, is it faster, more secure, to use Entity Framework (with the repository pattern) or to use ADO.NET with SqlConnection and SqlCommand?

推荐答案

非常普遍的问题,但一些想法。

Very general question but some thoughts.

性能:

普通的SqlCommand和DataReader的将是显著快,当涉及到性能,只要所有的开发有一个线索。随着.NET 4.5和EF 5好像EF会得到一个不错的性能提升,但普通的​​SQL总是会更快。

Plain SqlCommand and DataReader will be significantly faster when it comes to performance as long as all the developers has a clue. With .net 4.5 and EF 5 it seems like EF will get a nice performance boost but plain sql will always be faster.

在这里看到一些数字:<一href="http://blogs.msdn.com/b/adonet/archive/2012/02/14/sneak-$p$pview-entity-framework-5-0-performance-improvements.aspx">http://blogs.msdn.com/b/adonet/archive/2012/02/14/sneak-$p$pview-entity-framework-5-0-performance-improvements.aspx

普通ADO.NET还支持异步图案,这可能是在某些情况下非常重要。 EF没有。 ATLEAST不是EF 4。

Plain ADO.NET also supports the async patter which might be very important in some scenarios. EF doesn't. Atleast not for EF 4.

安全

普通的SQL可能是安全的,因为EF只要您使用paramaterized查询。 EF会做这个自动为您保护您免受SQL注入。由于EF总是给你这个,我会认为这是安全的,但有微弱的差距。

Plain SQL might be as safe as EF as long as you use paramaterized queries. EF will do this automatically for you to protect you from SQL injection. Because EF always gives you this I would consider it safer but with a slight margin.

可测性

我发现这是一个巨大的胜利,当涉及到EF。与其鬼混与嘲讽我跑对我的控制器的快速一体化测试使用SqlCe4。这是很容易做到这一点,只要你使用EF。

I have found this to be a big win when it comes to EF. Instead of fooling around with mocking I run fast intergration tests against my controllers using SqlCe4. It's very easy to do this as long as you use EF.

摘要

我觉得EF非常有能力和API是令人愉快的工作。如果你正在做的性能密集型的事情,你将不得不落入原SqlDataReader对象和使用SqlBulkCopy不时但将它们混合是没有问题的。我喜欢用EF在那里我可以忍受的性能损失,因为我更富有成效。当我觉得命中是很大的,我会用普通的SQL。

I find EF very capable and the API is pleasant to work with. If you are doing performance intensive things you will have to drop into raw SqlDataReader and SqlBulkCopy from time to time but mixing them is not a problem. I like to use EF where I can live with the performance loss because I'm more productive. Where I feel the hit is to big I will use plain Sql.

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

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