Entity Framework Tutorial Entity Framework vs NHibernate
Entity Framework vs NHibernate?
When trying to decide between using the Entity Framework and NHibernate as an ORM, what are the advantages and disadvantages of Entity Framework and NHibernate?
Entity framework and NHibernate are object-relational mapping frameworks. These can be used to map a database schema to domain objects in any object-oriented language.
- Entity Framework allows you to create a model by writing code or using boxes and lines in the EF Designer and generate a new database.
- You can write code against the Entity Framework, and the system will automatically produce objects for you as well as track changes on those objects and simplify the process of updating the database.
- One common syntax (LINQ) for all object queries whether it is a database or not and pretty fast if used as intended, easy to implement and less coding required to accomplish complex tasks.
- The EF can replace a large chunk of code you would otherwise have to write and maintain yourself.
- It provides auto-generated code
- It reduces development time and cost.
- It enables developers to visually design models and mapping of database
- EF also supports async database operations.
- You have to think in a non-traditional way of handling data, not available for every database.
- If there is any schema change in database FE won't work and you have to update the schema in solution as well.
- The EF queries are generated by the provider that we cannot control.
- It is not good for a huge domain model.
- Lazy loading is the main drawbacks of EF
- NHibernate has flexible and very powerful mapping capabilities.
- It supports a second-level cache, that can be used among multiple ISessionFactory
- Very polished Unit Of Work implementation.
- With NHibernate, you can use mostly any database you want
- It's very mature and popular in an enterprise environment.
- NHibernate supports different ID generation strategies, coming from the database such as;
- Identity (for SQL Server, MySQL, and databases who support identity columns);
- Sequence (for Oracle, PostgreSQL, and others who support sequences);
- Increased startup time due to metadata preparation
- Huge learning curve without ORM background.
- Writing XML mapping can be very tedious especially for big databases with hundreds and thousands of tables and views and stored procedures.
- NHibernate falls badly behind with regard to documentation because its process is outdated and resources for learning are scattered all over the Internet.