I have a stored procedure that logs some data, how can I call this with NHibernate?
So far I have:
ISession session = .... IQuery query = session.CreateQuery("exec LogData @Time=:time @Data=:data"); query.SetDateTime("time", time); query.SetString("data", data); query.?????;
What should the method ?????
be? Or am doing something more fundamentally wrong?
You can call an SQL stored procedure with the execute, open, or get statement; in each case, you use the #sql directive. A stored procedure is a set of instructions for a database, like a function in EGL.
Using SQL Server Management Studio Expand Databases, expand the database in which the procedure belongs, and then expand Programmability. Expand Stored Procedures, right-click the procedure and then click View Dependencies. View the list of objects that depend on the procedure.
You can use createSQLQuery() to call a store procedure directly. Declare your store procedure inside the @NamedNativeQueries annotation. -Call it with getNamedQuery().
ExecuteUpdate on SQL Query should help you.
Sample:
ISession session = .... IQuery query = session.CreateSQLQuery("exec LogData @Time=:time, @Data=:data"); query.SetDateTime("time", time); query.SetString("data", data); query.ExecuteUpdate();
This seems to be a limitation of NHibernate, from NHibernate Documentation:
The procedure must return a result set. NHibernate will use IDbCommand.ExecuteReader() to obtain the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With