Saturday, April 30, 2011
A data access layer usually consumes 30% of the development time. A reasonable ORM can save you 90% of that 30% time. One such big hit is NHibernate.
Steps to use NHibernate:
- Decide - Model first, Database first, or Code first
- Create Mapping
- Detached object
- Batch processing
- Fluent Syntax
- Database independency
- Pretty mature, and large community
- Open source
- Model classes are POCO
- No visual modeler
- Alot of mapping code that requires to be put into
- Classes must have a no-arg constructor
- Classes should have a private Long id;
- Classes may have private database attributes
- Clumsy mapping/configuration files
- No good LINQ to NHB! still under development – very, very young!
- Stored procedures in NHB; challenging.
- Increased startup time due to metadata preparation ( not good for desktop like apps)
- Huge learning curve, especially for those having no ORM background.
- Pretty challenging to fine-tune the generated sql. For instance, see following SQL:
- Hard to get session management right if used in non-typical environments ( read non webapps )
- Not suited for apps without a clean domain object model ( no all apps in world dont need clean domain object models) .
- Have to jump through hoops if you have badly designed ( legacy ) db schema.
|Test #||Operation||Time (ms)||NH|
|2||100 Reads - 3 Joins||001.844||Couldnt apply 3 level join in HQL! ツ|
|5||100 Reads - 1 Join||000.328||000.781|
FIG1: ADO.NET vs NHibernate
Happy coding! Btw, you may also like to refer to my other articles on similar topic: