Sorry to come in so late to the game, but I thought it worth while to
take a contrarian view and state that NH actually does support stored
procs with output parameters-- maybe not in the way you imagine.

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

On Jan 28, 1:46 am, Asier <[email protected]> wrote:
> Hello
>
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to