EntityFramework和NHibernate之间的区别? [英] Difference Between entityFramework and NHibernate ?

查看:198
本文介绍了EntityFramework和NHibernate之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都在Nhibernate和ADO.NET上工作.有人可以通过示例告诉我实体框架如何工作以及它比nhibernate有什么优势吗?

I have worked on Nhibernate and ADO.NET both.Can Anyone please tell me how entity framework works and what are it''s advantages over nhibernate with a Example ?

推荐答案

写批处理– NHibernate可以配置为批处理所有对数据库的写操作,因此当您需要向数据库中写多个语句时,NHibernate只会进行一次往返,而不是每个语句都去数据库.
读取批处理/多查询/期货– NHibernate允许将多个查询批处理到数据库的一次往返中,而不是每个查询单独进行往返.
批量加载集合–延迟加载集合时,NHibernate可以查找未加载的相同类型的其他集合,并将所有它们一次加载到数据库中.这是避免必须处理SELECT N + 1的好方法.
带有lazy ="extra"的集合–额外的惰性意味着NHibernate可以适应您可能在集合之上运行的操作.这意味着blog.Posts.Count不会强制加载整个集合,而是会从其中BlogId = 1的Posts"中创建一个"select count(*)"语句,并且Blog.Posts.Contains()也会得到结果在单个查询中,而不是付出将整个集合加载到内存中的代价.
集合过滤器和分页集合-这使您可以在实体集合的顶部定义其他过滤器(包括分页!),这意味着您可以轻松地对blog.Posts集合进行分页,而不必将整个内容加载到内存中.
2级缓存–管理缓存非常复杂,我之前谈到了为什么这很重要,因此如果现在就跳过.
调整–每当您需要的内容超出框架提供的内容时,这都是至关重要的.使用NHibernate,几乎在所有情况下,您都有一个扩展点,而使用EF,您将完全被完全阻止.
整合与可扩展性– NHibernate有很多扩展项目,例如NHibernate Search,NHibernate Validator,NHibernate Shards等.此类项目不仅对于EF不存在,而且在大多数情况下无法编写,因为EF没有扩展点可以说.


参考:
http://ayende.com/blog/4351/nhibernate-vs-entity-framework- 4-0 [^ ]
Write batching – NHibernate can be configured to batch all writes to the database so that when you need to write several statements to the database, NHibernate will only make a single round trip, instead of going to the database per each statement.
Read batching / multi queries / futures – NHibernate allows to batch several queries into a single round trip to the database, instead of separate roundtrip per each query.
Batched collection loads – When you lazy load a collection, NHibernate can find other collections of the same type that weren’t loaded, and load all of them in a single trip to the database. This is a great way to avoid having to deal with SELECT N+1.
Collection with lazy="extra" – Lazy extra means that NHibernate adapts to the operations that you might run on top of your collections. That means that blog.Posts.Count will not force a load of the entire collection, but rather would create a "select count(*) from Posts where BlogId = 1" statement, and that blog.Posts.Contains() will likewise result in a single query rather than paying the price of loading the entire collection to memory.
Collection filters and paged collections - this allows you to define additional filters (including paging!) on top of your entities collections, which means that you can easily page through the blog.Posts collection, and not have to load the entire thing into memory.
2nd level cache – managing the cache is complex, I touched on why this is important before, so I’ll skip if for now.
Tweaking – this is something that is critical whenever you need something that is just a bit beyond what the framework provides. With NHibernate, in nearly all the cases, you have an extension point, with EF, you are completely and utterly blocked.
Integration & Extensibility – NHibernate has a lot of extension projects, such as NHibernate Search, NHibernate Validator, NHibernate Shards, etc. Such projects not only do not exists for EF, but they cannot be written, for the most part, because EF has no extension points to speak of.


refer:
http://ayende.com/blog/4351/nhibernate-vs-entity-framework-4-0[^]


这篇关于EntityFramework和NHibernate之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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