开发者

NHibernate - how to call a stored procedure?

开发者 https://www.devze.com 2023-01-01 16:39 出处:网络
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 - ca

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>();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号