For those of you who are having trouble locating an example of how to actually execute a stored procedure with NHibernate, please see the below code that I use to execute mine.
*** MAPPING FILE ***
<sql-query name="MyStoredProcedure">
<return alias="MyObject" class="My.Namespace.MyObject, My.Namespace">
<return-property name="Id" column="ID"/>
<return-property name="Username" column="USERNAME"/>
</return>
exec MyStoredProcedure :PrimaryKey, :Username
</sql-query>
*** EXECUTION CODE (c#) ***
ISession session = base.NHibernateSession;
IQuery query = (IQuery)session.GetNamedQuery("MyStoredProcedure");
query.SetParameter("PrimaryKey", theValue);
query.SetParameter("Username", theValue);
return (MyObject)query.UniqueResult();
Hope this helps. I spent many hours trying all different combinations until this finally worked.
|