经典 ADO.NET 还是实体框架更适合大规模数据库事务?
我们刚刚开始一个使用 .NET 3.5 和 MSSQL 2008 开发 Web 门户的项目。有人提出一个问题,对于处理涉及数万甚至数十万条记录的数据访问,哪一个是明智的选择?我在某处看到一个表,比较了 ADO.NET、EF 和 LINQ to SQL,看起来 LINQ to SQL 平均速度最慢,但 ADO.NET 在大型操作上遇到了阻碍。
顺便问一下,您对于大规模使用 NHibernate 有什么想法?
We just started on a project to develop a web portal using .NET 3.5 and MSSQL 2008. A question was raised on which is the sensible choice to handle data access which involves tens of thousands of records up to hundreds of thousands? I saw a table somewhere that compared ADO.NET, EF and LINQ to SQL and it seemed like LINQ to SQL is the slowest by average but ADO.NET choked on large operations.
By the way, what are your thoughts on using NHibernate on a large scale?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
归根结底,一切都将使用 ADO.NET。
我可能会使用存储库模式编写一个概念验证应用程序(一个存储库使用实体框架,另一个使用原始 ADO.NET)。
运行一些测试,看看哪种方法更适合您的需求。
我将告诉您,使用普通 ADO.NET 将使您能够更精细地控制数据库中实际执行的内容。
Everything is going to use ADO.NET when it boils down to it.
I would probably write a Proof of Concept app using the Repository pattern (with one repository using Entity Framework and the other using raw ADO.NET).
Run some tests and see which method suits your needs better.
I will tell you that using vanilla ADO.NET will give you finer grain control over what is actually being executed against your database.
Linq2Sql 和 EF 都将源代码转换为 T-Sql(如果使用 MS SQL)。速度根据它们转换为 sql 的方式而有所不同。请记住,您始终可以使用其中任何一个来调用您自己的 sql (s-procs),从而在生成的 sql 执行得不够好时,可以更好地控制针对您的存储执行的内容。
Both Linq2Sql and EF translate your source code into T-Sql in case with MS SQL. The speed varies based on how they translate to the sql. Remeber, you can always call your own sql (s-procs) using either one, thus having more control over whats being executed against your store for the cases when the generated sql is not performing well enough.
StackOverflow.com 使用
LINQ-to-SQL
。我猜他们现在正在处理数十万条记录。 SO 的表现你的团队可以接受吗?正如其他人所说。无论如何,它最终都是一样的,
T-SQL
。 ORM 是关于函数式编程和软件设计的。始终可以对底层查询进行优化。仅仅因为某人的测试表明它在特定情况下表现更好而使用普通ADO.NET
对我来说似乎是一个糟糕的理由。LINQPad
是一个非常有用的工具,用于比较框架和优化查询。如果您还没有,您应该检查一下。StackOverflow.com uses
LINQ-to-SQL
. I'd guess they're working with hundred of thousands of records by now. Is SO's performance acceptable to your team?And as others have said. It ends up being the same thing anyways,
T-SQL
. ORMs are about Functional programming and software design. Optimizations of the underlying queries can always be made. Using vanillaADO.NET
just because someone's test showed it to perform better in that specific circumstance seems like a bad reason to me.LINQPad
is a very useful tool for comparing frameworks and optimizing queries. If you haven't already, you should check it out.