tags:

views:

408

answers:

2

The project on which i am working has a very complex business and data logic. I have around 90 tables and 250 stored procedures in my database.

I have seen very basic samples on Nhibernate through which the operations are performed on database.

I just want to know if we have a huge complex logic then how can we use nhibernate.

Also currently in some scenarios I handle the business logic at stored procedure level so if there is a slight change just making some changes in stored procedure sets things right for me. But if i am using Nhibernate how can i work with stored procedures and create complex situations work for me.

Can i get sample code in C# which uses nhibernate and contains complex real world scenarios.

+1  A: 

Not only can stored procedures be called through NHibernate, but the ORM enables you to call these procedures in such a way that their result sets are converted automatically to specific entity types.

See http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!241.entry for an example. Specifically, you need to use the <sql-query> element of NHibernate's mapping files to set up the name, input parameters, and return type for your stored procedure. You can then refer to this stored procedure in code by the name you've provided.

I don't believe you can call stored procedures nakedly. They have to be given a name somewhere within the NHibernate mapping files.

As for complexity, I am completely on board with the challenges you're facing. I'm giving NHibernate a test run in my own projects to measure its performance and how much it boxes you in when you need flexibility. So far, I haven't had any issues.

David Andres
+3  A: 

An ORM such as NHibernate's primary goal is to abstract database access from the application and render it database agnostic. Having business logic inside stored procedure means that using an ORM will not bring any value whatsoever. Using plain ADO.NET would be more straightforward and beneficial. IMHO using NHibernate to call plain SQL or stored procedures is useless. You are just putting an additional layer to your application that wouldn't bring any value.

However if you move the business logic away from the database and have a nice object model an ORM could be really helpful to map this model to database tables.

Darin Dimitrov
I agree with you, but I do believe that an ORM will take care of 95% of your data-access needs. However, there are scenarios where you want to optimize beyond what an ORM can offer, so it's helpful to be able to call into SPs when the need arises.
David Andres
I think that having 250 stored procedures!! as in the OP's case is not "when the need arises", it's just the way the application is designed. "when the need arises" would be if you had for example a couple of legacy stored procedures you need to call in some rare cases. That's why I proposed using what's best in this case which is ADO.NET.
Darin Dimitrov