nhibernate, stored procs
Can we call a STOREDPROC which inserts data into db which开发者_开发知识库 has no return value from NHIBERNATE? If so can any one please help me out with a small sample.
I don't know if it works if you define the query in XML, but you can simply create an ISQLQuery
and call ExecuteUpdate()
on it.
Use ADO.NET, -Get Connection object from NHibernate session, -Create a Dbcommand -Set your procedure in Dbcommand text -Run the command
Note: NHibernate might supprot stored procs but its a complicated process refer to this link, so opt ADO.NET which is optimum in your scenario.
This is one way:-
In your mappings file:-
<sql-query name="UpdateMeetingsSentFromTeamLeader">
<![CDATA[exec uspUpdateMeetingsSentFromTeamLeader :MeetingId]]>
</sql-query>
and your code is:-
public void UpdateMeetingsSentFromTeamLeader(int meetingId)
{
Session
.GetNamedQuery("UpdateMeetingsSentFromTeamLeader")
.SetInt32("MeetingId", meetingId)
.ExecuteUpdate();
}
精彩评论