On SubSonic & NHibernate

time to read 5 min | 893 words

I recently got this email, and the author has kindly given me permission to post the email and my response to it:

At this moment, I will be suggesting to my project team in my company to use ORM, hopefully to make our software development faster especially on the data layer side. We use LLBLGen (the old one), and we really have plenty of stored procedures which were hard to maintain.

I also noticed about subsonic today. I watched the videos and were impressed about it.

1)  However I am not too clear about the difference between subsonic and nhibernate. It looks so alike, furthermore both of them have so much similarities with LINQ. What is your view on this? Most people mentioned that nhibernate was bloated.. something like that which I wasn't clear about it.

2)  When LINQ release, I should scrap off either subsonic or nhibernate for this platform. As LINQ is built into the language itself, it is easier to extend. I am aware that there is something like LINQ for NHibernate. Are these 2 the same technology or ???

3) Is nhibernate ready to be used in real enterprise commercial projects? Will there be any payment to it? Or it is completely free?

4) Last but not least, I am not too sure whether nhibernate does code generation like subsonic. But I did heard that nhibernate relied on codesmith, which you needed to purchase codesmith.

Well, obviously I prefer NHibernate, that has absolutely nothing to do with anything about SubSonic, I am simply strongly biased toward NHibernate. That said, let me try to summarize what I think the difference between the two are.

NHibernate and SubSonic takes two different approaches toward OR/M, NHibernate has the "objects is all you see" approach, while SubSonic is much closer to the way that the database view of the world. You still deals with some of the stuff from ADO.Net directly, but SubSonic takes most (all?) of the pain from that. From going over the docs, it looks like SubSonic has a fairly complete support for object view of the world.

Both are valid approaches, and choosing between them is a matter of what you are more comfortable with, and what do you want to accomplish. If you are trying to build a Domain Driven application, NHibernate is the preferred approach, if you are building on an existing database, with existing stored procedures, you should probably see if SubSonic would be right for you.

I would probably not choose that, but I am biased, as I said. I should mention that NHibernate is supplying the OR/M bits only, SubSonic seems to do more than that, code generation, integration with EntLib, WebForms controls, etc.

Now let me try to answer the questions themselves.

1/ There is a difference between Linq and the OR/M that are built on Linq (Microsoft & Naming again). Linq is a set of extensions to the language, which opens up interesting approaches for set based logic in imperative language. In other words, it is wonderful syntactic sugar, and I am looking forward to be able to making use of that in creative ways.

Linq for Sql is an OR/M whose query language is Linq queries, as far as I can see, this is a good approach from Microsoft, but it is limited to SQL Server only, and lacks some of the essentials features that I, as an advance user of OR/M needs. For most basic scenarios, I believe it should suffice.

NHibernate bloated... I haven't heard this before, and I would be interested to know by what criteria.

2/ No, you certainly should not. As I explained, Linq and the Linq for Sql product are two different things. From the way Microsoft is positioning Linq for Sql, I would assume that it would be harder to extend. Linq for NHibernate is a way to query NHibernate using Linq, that is all. You get the nice Linq syntax and the power from NHibernate. I would assume that SubSonic would have similar features (if it doesn't have it already).

3/ NHibernate is more than ready. It is the backbone for quite a lot of enterprise commercial projects right now. It is completely free, and require no payment. Commercial support can be had from JBoss or my company.

4/ NHibernate doesn't do code generation, that is outside the scope of the OR/M. There are several code generators that will output NHibernate mapping and classes, including free ones. CodeSmith certainly has some good templates for NHibernate, but it is not the only one by far.

At the end, it comes done to evaluating whatever you can be effective with the tool in the approach that you prefer. You mentioned that you are currently suffering from pain as a result of hard to maintain stored procedures. Take NHibernate for a spin on your database, see if you are productive, then take SubSonic and do the same. That are numerous sources of information about both, so it shouldn't be a problem to get started.

Either way, have fun, and remember to choose by what will make your life easier, both now and in the long run.