views:

589

answers:

1

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.

+3  A: 

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 objet that runs the native query.

Vitaly Polonetsky
Good point! I didn't notice that...
Andy White
Bingo, that did it. Thanks