Archives
- Newer posts
- November 2024
- April 2024
- November 2023
- October 2023
- August 2023
- May 2023
- February 2023
- October 2022
- August 2022
- July 2022
- May 2022
- April 2022
- March 2022
- February 2022
- June 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- August 2016
- June 2016
- April 2016
- March 2016
- February 2016
- January 2016
- July 2015
- June 2015
- Older posts
.Net Applications with ORMs
Now-a-days all web applications make use of a good ORM framework. During the early days of coding, we used simple ADO.NET by using classes such as SqlCommand, SqlDataReader, SqlDataAdapter, and DataSet. As days went by, ORMs took the lead and programmers preferred to use them instead of plain old ADO.NET.
With ASP.NET, the ORMs that are commonly used are:
– ADO.NET Entity Framework
– LINQ to SQL
– NHibernate
There are also a few others like Dapper and Massive and the Enterprise Library Data Access Application Block.
When it comes to making a choice between Entity Framework and NHibernate, majority of the developers prefer Entity Framework, because it is a Microsoft product and it comes bundled in the IDE. Being a .Net developer, I too would agree with the majority of the team that Entity Framework would be my first choice. But the first ORM that I used was NHibernate.
The first project that I worked on had the map files written using NFluent NHibernate. I admit, it was difficult to create the classes, especially for associations (many-to-one, one-to-many and many-to-many). But it was fun to learn. Once we came across an issue where the application would stop working, due to overflow exception. It took us days to figure out the issue. Luckily we had a tool ‘NHibernate Profiler’, it pointed out a mistake in one of the classes, where the association was wrongly written. And that bug came to light after about 1000 records were inserted. Earlier as the data was less and it had no primary key/foreign key conflicts, it ran smoothly. But later as the data increased, problems started causing deadlock with associations.
The second project that I worked on, also used NHibernate. But it used the hbm files in xml and not the NFluent one. So it was much easier. And the best part was that – that client had purchased the tool ‘CodeSmith Generator’. All we had to give as input was the DB and it generated the manager files, the hbm files, on the fly. This saved us a lot of time and effort to create the mapping files. But of course, it had the cost associated with it.
Well, if we compare NHibernate with Entity Framework, the latter is much simpler. It was introduced in Microsoft .NET 3.5 Service Pack 1. The edmx file is generated for us. All this comes within the .NET Framework. So it is free and compatible and the learning curve is not steep at all. Entity Framework works well with MSSql. For other databases, connectors are required. Using NHibernate, we can fire multiple queries at one time, which is not the same in Entity Framework. But NHibernate takes a longer time to initialize compared to Entity Framework. That is the only drawback, other than the learning curve.
Both are good in their own way and better than traditional ADO.NET as they do reduce the lines of code to a great extent.