views:

100

answers:

2

Hi,

Is reading the database records from the Database using Stored Procedures in NHibernate a good approach?If yes then why or if No, then also why? The application has only the feature of reading values from the database using NHibernate in the data access layer no updates and no inserts just only retrieval.

+4  A: 

In my opinion, stored procedures are only necessary if you handle a vast amount of data. The performance is better, because the database managament system can use its optimization routines to fasten the access to the stored data.

The scond reason not to use stored procedures is, that you want to separate the dbms and your application. So you can change the database system if you want to. If you use stored procedures your bound to this specifig dbms (ie. oracle).

MoJo2600
I was just about to answer pretty much the same thing. If you have a choice, I would not use sp's. It is a lot harder to maintain and work with.
Mattias Jakobsson
+1 Exactly the answer I'd have given as well.
David M
waste = vast? fasten?
Michael Maddox
yeah, waste = vast, sorry
MoJo2600
Stored procedures being faster than raw sql is a myth. NHibernate correctly generates parametrized sql which will be cached in the DB in a similar way to a stored proc would be.
Chris Marisic
I stick with Mr. Chris Marisic. I no longer believe that SP's are faster these days, as we meet with "new age" technologies. If you're using VB6, VC++ or so, perhaps it's a better approach. But as long as .NET is concerned, and either Java (Struts and Hibernate), I can't imagine that we have not evolved so that SP's would still be of better performance.
Will Marcouiller
+2  A: 

Is reading the database records from the Database using Stored Procedures in NHibernate a good approach?

If you are hydrating data grids, no. While NHibernate will allow for this scenario, it is a poor use of NHibernate as NHibernate is not adding much value. Why take a dependency on NHibernate for basically nothing in return?

If you are hydrating objects, yes. NHibernate is at least serving a minimal purpose of mapping the results returned from the stored procedure to an object. You are taking a significant dependency for one tiny feature, but it's probably better than rolling your own solution.

The answer would basically be the same for any .NET ORM, assuming the ORM can hydrate objects based on the data returned by a stored procedure.

Michael Maddox
I fully agree with Mr. Micheal Maddox. This is a great dependancy for not much of a gain regarding developing time. ORM tools are given they accelerate your development time, furthermore, they allow you to concentrate your the business logic instead of the DML (Data Manipulating Language).
Will Marcouiller