NHibernate - how to call a stored procedure?
I want to call a stored procedure from My nHibernate application. That stored procedure returns a list and I will return back开发者_StackOverflow中文版 to the UI. How to call the stored procedure - can anyone help me on this?
You can use the following example. In you mapping file define the query
<sql-query name="MyNameQuery">
<return-scalar column="SomeColumn" type="String"/>
<![CDATA[exec proc_MyProc ?]]>
</sql-query>
For the call you can do following
ISQLQuery objQuery = MySession.GetNamedQuery("MyNameQuery") as ISQLQuery;
objQuery.SetParameter(0, "1"); // stored procedure expects a parameter, not used here
var myResult = objQuery.List<string>();
精彩评论