Question

I am relatively new to Nhibernate. I am trying to update a stored procedure. I got the below section in the named query.

<sql-query name="TestUpdate">
exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField
</sql-query>

Testupdate is a stored procedure which will has a simple update statement in it. I am updating the parameters using the following line of code.

        int? testdata = null;
        IQuery query = Session.GetNamedQuery("TestUpdate");
        query.SetDateTime("DateField", DateTime.Now.AddDays(10));
        query.SetString("StringField", "UK");
        query.SetInt32("IntField", 100);
        query.SetBoolean("BoolField", true);

        if(testdata.HasValue)
            query.SetInt32("NullIntField", testdata.GetValueOrDefault());
        else
        {
            query.SetParameter("NullIntField", null,NHibernateUtil.Int32);    
        }

        var cmd  = new SqlCommand(query.QueryString, (SqlConnection)Session.Connection);
        cmd.ExecuteNonQuery();

However, when I look at the value of query.QueryString, it still points to the same value (exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField). It seems like the named parameters are not getting assigned. What should I do to get around this problem?

I am using SharpArchitecutre, which uses fluent nhibernate to query the data.

Please note, I have searched the forum for this particular issue and I couldn't land on an example.

I am sure the issue could be trivial, but I couldn't find a solution so far.

Any help is appreciated.

Was it helpful?

Solution

There is little support for stored procedures in NHibernate. For more information, check out the NH documentation: http://nhibernate.info/doc/nh/en/index.html#querysql-limits-storedprocedures

And perhaps this might help you along: http://ayende.com/blog/1692/using-nhibernate-with-stored-procedures

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top