How do I call a stored procedure from NHibernate that has no result?

thatismatt picture thatismatt · Jul 7, 2009 · Viewed 42.3k times · Source

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?

Answer

Sathish Naga picture Sathish Naga · Jul 7, 2009

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