决定NHibernate与实体框架? [英] Deciding between NHibernate vs Entity Framework?

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

问题描述

NHibernate和Entity Framework 4.0的主要优点和缺点是什么?

What are the main advantages and disadvantages of NHibernate and Entity Framework 4.0?

(在标记我的问题时,我注意到比EF更多的NHibernate标签NHibernate更受欢迎?)

推荐答案

我对EF的经验非常有限(几个博文和教程),但有很多NHibernate的经验。

I've had very limited experience with EF (a few blog posts and tutorials), but plenty of experience with NHibernate.

微软一直是OpenSource运动的背后,NHibernate绝对是这样。当EF 1.0首次发布时,它缺乏对POCO支持和持久性无知等关键功能的支持,它要求您的实体类从EF扩展基本实体类,因此您的实体类并未完全从EF分离。这实现了可维护性和单元可测性,以及如果需要,可以切换ORM提供者。

Microsoft is consistantly behind where the OpenSource movement is, and this is definitely the case with NHibernate. When EF 1.0 was first released, it lacked support for key features such as POCO support and persistence ignorance, it required your entity classes to extend a base entity class from EF, so your entity classes weren't completely decoupled from EF. This effected maintainability and unit testability, as well as the ability to switch ORM providers if need be.

另一方面,NHibernate允许您将您的实体与NHibernate本身完全分离。 EF 4.0在这方面有所回落,它是Code First Development方法(最近由Scott Guthrie发布)是朝着正确方向迈出的一步。

NHibernate on the other hand allowed you to completely decouple your entities from NHibernate itself. EF 4.0 has caught up somewhat in this regard, it's Code First Development approach (recently announce by Scott Guthrie) is a step in the right direction.

NHibernate本身有一些非常强大的映射功能,如继承映射,组件类的映射(在Customer实体上认为Address对象),单向实体关联映射。您可以充分利用域模型中面向对象编程(封装,多态,继承等)的优势,将实体类作为封装行为,而不仅仅是数据容器。如果您希望根据域驱动设计的原则构建您的域模型,那么NHibernate是非常适合这个。我不能直接在EF 4.0上直接发表这些观点,只从我从其他NHibernate用户那里听到的尝试使用EF 4.0,但EF 4.0仍然落后于这些领域,但正在获得成功。

NHibernate itself has some very powerful mapping capabilities such as Inheritance mapping, mapping of component classes (think Address object on a Customer entity), unidirectional entity association mapping. It lets you take full advantage of the power of Object Oriented programming (Encapsulation, Polymorphism, Inheritance etc.) inside your domain model, think of your entity classes as encapsulating behavior and not just data containers. If you're aspiring to build your domain model to the principles of Domain Driven Design, then NHibernate is a very good fit for this. I can't speak directly on EF 4.0 on these points, only from what I hear from other NHibernate users trying to use EF 4.0, but EF 4.0 still lags behind in these areas, but it's gaining ground.

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

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