nHibernate and ADO.Net Entity framework are ORM frameworks (object relational mapping frameworks).
Entity framework is the Microsoft’s first ORM framework. Microsoft introduced ADO.NET Entity framework in .net framework 3.5 Service Pack 1.
In an object oriented language, object relational mapping framework is used to map database schema to corresponding domain objects.
These ORM framworks are very helpful to map database data in your persistence layer of application code without the need of writing data access code.
nHibernate Vs Entity Framework
There are some variations in using nHibernate over Entity framework. Also there are some advantages of nHibernate as compared to entity framework as an ORM.
Listing below the advantages of nHibernate over entity framework.
- nHibernate works with pure POCO classes. But entity framework models are not pure POCO classes, they also comprises some lower level functionality along with business properties to work with database
- nHibernate supports all major types of databases but Entity framework works perfectly with MSSQL and some need additional connectors to support other databases than MSSQL
- nHibernate can be extended in terms of data loading, custom column types, custom collections, SQL generation, etc. Entity framework has restricted extension points.
- Write batching – In nHibernate, we can be configure 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) – nHibernate allows to batch several queries into a single round trip to the database, but in entity framework there need separate roundtrip per each query.
- nHibernate provisions lazy loading for scalar properties like BLOB, CLOB. Entity framework does not supports lazy loading.
- nHibernate has support for extended cascading deletion of rows.
- nHibernate has more events included like preload, postload, updation, deletion.
- nHibernate has support for 2nd level cache.