Is true that Nhibernate doesn’t support stored procedures output
parameters?
Thanks.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
The reason for my question was that, I am working with a legacy DB
(IBM DB2). There is an access restriction, and we can only use stored
procedures. I thought NHibernate was a good approach for this but
maybe no.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Legacy-DB + strongly DBA restriction = legacy DAL = big PITA
Putting all arguments aside about whether, philosophically, this is a
"good practice," you can use standard ADO.NET commands that are
wrapped in NH sessions and transactions like so:
using (ITransaction transaction = Session.BeginTransaction())
{
// build an ADO command
IDbCommand command = new SqlCommand();
// give it the connection we're using from NH
command.Connection = Session.Connection;
// tell the NH transaction to use the ADO command
transaction.Enlist(command);
// set some command properties
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "dbo.spYourStoreProcNameGoesHere";
// set input params
var param = new SqlParameter("@InputParam", SqlDbType.Int);
param.Value = inputParam;
command.Parameters.Add(param);
//... add any other input params
// set up the output param
var outputParam = new SqlParameter("@OutputParam", SqlDbType.Int);
outputParam.Direction = ParameterDirection.Output;
command.Parameters.Add(outputParam);
// execute the command
command.ExecuteNonQuery();
// grab the return value casting it appropriately
return (int)((SqlParameter)command.Parameters
["@OutputParam"]).Value);
}
Now, it _is_ true that using the ADO commands this way can create some
issues. Notably, if you're using caching, and the stored proc changes
data in any way in the database, then the cache is invalid and you'll
need to handle that. However, wrapping the ADO command in the NH
session does give you access to the overall NH ISession
infrastructure, including any interceptors that you have registered.
Sorry for the long post, but as you can see, NH does support the use
of stored procs that return output parameters.
Although I also agree that stored procs are evil, sometimes we do what
we want, but most of the time we do what we must. As an example, I
have just taken up a new position with a company that has over 500K
lines of code in stored procs. We _must_ continue to use stored procs
as we begin our transition to more current best practices for software
architecture and development that we _want_.
Regards,
-devon