user17510
user17510

Reputation: 1549

Hibernate NHibernate - Native SQL

Trying to delete an unmapped class/record via the NHibernate sql api. But can't seem to get it working. Does anything look wrong with this?

session = NHibernateHelper.GetCurrentSession();

        tx = session.BeginTransaction();
        using (tx)
        {
            session.CreateSQLQuery("DELETE FROM tb_category WHERE parentID = :parentID").SetInt64("parentID",pID);

            tx.Commit();
        }

Any help appreciated.

Upvotes: 0

Views: 2298

Answers (1)

m_vitaly
m_vitaly

Reputation: 11952

I think, you have to execute the Query to make it do something.

You're just creating a Query and setting it's parameters.

In Hibernate there is an .executeUpdate() method for the SQLQuery object that runs the native query.

Upvotes: 4

Related Questions