Insert using strored procedure from nhibernate

Posted by jcreddy on Stack Overflow See other posts from Stack Overflow or by jcreddy
Published on 2010-06-09T10:34:17Z Indexed on 2010/06/09 10:42 UTC
Read the original article Hit count: 189

Filed under:
|

Hi I am using the following code snippets to insert values using stored procedure. the code is executing successfully but no record is inserted in DB.

Please suggest with simple example.

**---- stored procedure--------**
Create PROCEDURE [dbo].[SampleInsert]
    @id int, @name varchar(50)
AS
BEGIN   
    insert into test (id, name) values (@id, @name);
END

**------.hbm file-------**
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <sql-query name="Procedure">
    exec SampleInsert
    :Id,:Name
  </sql-query>
</hibernate-mapping>

**--------c# code to insert value using above sp------**
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
IQuery query = session.GetNamedQuery("Procedure");
query.SetParameter("Id", "222");
query.SetParameter("Name", "testsp");
query.SetResultTransformer(new NHibernate.Transform.AliasToBeanConstructorResultTransformer(typeof(Procedure).GetConstructors()[0]));

Regards Jcreddy

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about insert