How to write NHibernate to execute a Stored Procedure that does not returns a result set [Resolved]

Posted by Kasani007 under C# on 5/31/2016 | Points: 10 | Views : 471 | Status : [Member] | Replies : 1
<pre lang="C#">
How To Write The Method To Update The Tables Using StoredProcedures Of Oracle By Using NHibernate Without returning any ResultSet...i had used the below code but it is showing exception at query.SetResultTransformer();
i.e.,{"ORA-06550: line 1, column 7:\nPLS-00201: identifier 'STUDENT_DATA' must be declared\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored"}

public TOut ExecuteScalarStoredProcedure&lt;TOut&gt;(string procedureName, IList&lt;SqlParameter&gt; parameters)
{
TOut result;

using (var session = _sessionFactory.OpenSession())
{
var query = session.GetNamedQuery(procedureName);
AddStoredProcedureParameters(query, parameters);
result = query.SetResultTransformer(Transformers.AliasToBean(typeof(TOut))).UniqueResult&lt;TOut&gt;();
}

return result;
}</pre>





Responses

Posted by: Bhuvanesh6 on: 7/26/2016 [Member] Starter | Points: 50

Up
0
Down

Resolved
The procedure must return a result set. NHibernate will use IDbCommand.ExecuteReader() to obtain the results.

ISession session = ....
IQuery query = session.CreateSQLQuery("exec LogData @Time=:time, @Data=:data");
query.SetDateTime("time", time);
query.SetString("data", data);
query.ExecuteUpdate();

Refrence: http://stackoverflow.com/questions/1091521/how-do-i-call-a-stored-procedure-from-nhibernate-that-has-no-result

Bhuvan

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response