Insert using strored procedure from nhibernate
- by jcreddy
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