实体框架与 nHibernate 的性能、学习曲线整体特征
我知道这个问题已经被问过好几次了,我也阅读了所有的帖子,但它们都很旧了。考虑到版本和发布已经取得了进步,我希望可能会有新的观点。
我们正在 ASP.NET MVC 上构建一个新应用程序,需要最终确定 ORM 工具。我们以前从未使用过 ORM,并且几乎可以归结为两个 - nHibernate 和 nHibernate。实体框架。
我真的需要使用过这两种工具并可以根据经验推荐的人提供一些建议。我主要关注三点来最终确定 -
- 绩效
- 学习曲线
- 整体能力
我们将非常感谢您的建议。
此致,
I know this has been asked several times and I have read all the posts as well but they all are very old. And considering there have been advancements in versions and releases, I am hoping there might be fresh views.
We are building a new application on ASP.NET MVC and need to finalize on an ORM tool. We have never used ORM before and have pretty much boiled down to two - nHibernate & Entity Framework.
I really need some advice from someone who has used both these tools and can recommend based on experience. There are three points that I am focusing on to finalize -
- Performance
- Learning Curve
- Overall Capability
Your advice will be highly appreciated.
Best Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会使用 Nhibernate。我会选择 Sharp Architecture 作为一个很棒的框架,它封装了 NHibernate、ASP.NET MVC 和许多其他开源工具成为一个连贯的整体,这将为您提供坚实的架构基础。
Nhibernate 比 EF4 更成熟。它得到了社区的大力支持。只要您愿意时不时地亲自动手,您就会喜欢它。它对 LINQ 的支持目前还比较弱,但正在迅速改善。学习曲线还不错,但是会话管理之类的东西一开始可能会有点混乱。我喜欢 Sharp Architecture 的原因之一是他们拥有您需要的所有 NHibernate 东西,以及关于如何在 ASP.NET MVC 项目中正确使用它的大量指导。
EF4 具有 MS 批准印章。现在已经相当不错了,但仍落后于 NHibernate。这是一个非常好的选择,您会发现来自 MS、MS 支持的大量文档,并最终找到更多熟悉来龙去脉的开发人员。我还应该提到,Sharp 架构人员正在将对 EF4 的支持添加到他们的整体框架中。他们仍然支持 NHibernate,但如果您愿意,您也可以使用 EF4。
I would use Nhibernate. I would pickup Sharp Architecture as a great framework that wraps NHibernate, ASP.NET MVC and a bunch of other open-source tools into a coherent whole that will give you a solid architectural foundation.
Nhibernate is more mature than EF4. It is well supported by the community. As long as you are willing to get your hands dirty from time to time, you will like it. It's support for LINQ is currently a little weak but it is rapidly getting better. The learning curve is not bad, but things like session management can be a little confusing at first. One of the reasons I like Sharp Architecture is they have all the NHibernate stuff you will need in place and plenty of guidance on how to use it properly in an ASP.NET MVC project.
EF4 has the MS stamp of approval. It is pretty good now but still behind NHibernate. It is a perfectly good choice and you will find lots of docs from MS, MS support and eventually more developers that are familiar with the ins and outs. I should also mention that the Sharp Architecture folks are adding support for EF4 to their overall framework. They will still support NHibernate, but you will be able to use EF4 if you like.
我觉得学习NHibernate需要更多的时间。
EF 提供图形设计器,不幸的是 NHibernate 没有通用设计器。顺便说一句,这不是问题。如果您以领域驱动 (DDD) 方式进行设计,您将首先设计您的实体,并且您不关心数据库结构(如您以前那样),NHibernate 将为您处理该问题。
EF 4 更接近 NHibernate。我不会开始使用 EF 3.5,它缺少很多功能。
如果您乍一看觉得 NHibernate 太复杂,您可以从构建在 NHibernate 之上的框架开始。 ActiveRecords 和 Sharp Architect 就是很好的例子。
AFAIR EF 3.5 仅支持 SQL Server 2000。它无法处理 SQL Server 2005 中的新数据类型。我没有有关 EF 4 的信息,但我认为它支持这些改进。
如果您在实际应用程序中使用 NHibernate,则必须构建基础架构。例如,我实现了工作单元和存储库模式,以便能够在我的应用程序中编写测试并创建层。使用 EF 时您必须期待同样的情况。在 EF 3.5 中分离和附加实体并不是一件容易的事情,我必须编写棘手的扩展方法来将字段标记为脏等等。我希望他们在 EF 4 中解决了这个问题。NHibernate 就不存在这样的问题。
您不必在 NHibernate 中编写 HQL 查询,您可以使用 LINQ 提供程序。我认为这非常重要。 :)
总而言之NHibernate是一个成熟的产品,拥有良好的社区和商业支持。 EF 很年轻,但得到了 Microsoft 的大力支持。哦,EF 是 Microsoft 独有的东西,而您也可以将 NHibernate 知识移植到 Java。这对你很重要。
I think it takes more time to learn NHibernate.
EF provides graphical designer, unfortunately NHibernate doesn't have a generic designer. BTW it's not a problem. If you design in domain-driven (DDD) manner, you will design your entities first and you don't care about database structure (as you used to), NHibernate will handle that for you.
EF 4 got closer to NHibernate. I wouldn't start working with EF 3.5, it lacks a lot of features.
If you think NHibernate is too complicated at first sight, you can start with frameworks built on top of NHibernate. ActiveRecords and Sharp Architect are good examples.
AFAIR EF 3.5 supported only SQL Server 2000. It couldn't handle the new data types from SQL Server 2005. I have no information on EF 4 but I suppose it support these improvements.
If you use NHibernate in real word applications, you have to build an infrastructure. E.g. I implemented the Unit of Work and Repository patterns to be able to write tests and create layers in my application. You have to expect the same using EF. Detaching and attaching entities in EF 3.5 was not an easy thing, I had to write tricky extension methods to mark fields dirty and so on. I hope they solved it in EF 4. There is no such problem with NHibernate.
You don't have to write HQL queries in NHibernate, you can use the LINQ provider. I think it's very important. :)
All in all NHibernate is a mature product with good community and commercial support. EF is young but strongly supported by Microsoft. Oh, and EF is a Microsoft-only thing while you can port your NHibernate knowledge to Java as well. It this counts for you.
我正在尝试调查这个...
在将应用程序构建到两者中之后,NHibernate 肯定更强大,但它也相当笨重,而 EF 非常干净。在使用 Rails/ActiveRecord 后,相比之下,两者的功能都非常丰富,所以任何一个都肯定可以工作!
我注意到 NHibernate 会跟踪它刚刚运行的内容,如果它刚刚运行了一条语句,它就不会再次执行它,因此设计正确的应用程序将运行最少的数据库语句。我知道 EF 也不是很慢,但我不确定它是否以相同的方式缓存语句和结果。对于大型应用程序,这可以节省一些数据库资源!
简而言之,NHibernate 提供功能和可配置性,EF 4.0 提供简洁性和快速简单的学习曲线。另外,人们应该期望 EF 在下一两个版本中也可能在功能上赶上或超越 NHibernate,因此对这两个版本有一定的熟悉可能是有意义的。
I'm trying to look into this...
After building apps into both, NHibernate is definitely more powerful, but it's also quite clunky where EF is very clean. And after working with Rails/ActiveRecord, both are very feature rich in comparison, so either would definitely work!
I noticed that NHibernate keeps track of what it just ran, and if it just ran a statement, it doesn't exectute it again, so a properly designed app will run minimal database statements. I know that EF is not exactly slow either, but I'm not sure if it caches statements and results in the same way. For a large app, this could save some database resources!
So in short, NHibernate for functionality and configurability, and EF 4.0 for cleanliness and a quick easy learning curve. Also, one should expect EF in the next version or two should may catch up to or surpass NHibernate in functionality too, so it may make sense to have some familiarity with both.
看看这个
http://gregdoesit.com/2009/08/ nhibernate-vs-entity-framework-a-performance-test/
just take a look at this
http://gregdoesit.com/2009/08/nhibernate-vs-entity-framework-a-performance-test/