Hibernate NHibernate - 原生SQL [英] Hibernate NHibernate - Native SQL

查看:126
本文介绍了Hibernate NHibernate - 原生SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过NHibernate sql api删除未映射的类/记录。
但似乎无法让它工作。这有什么看起来不对?

  session = NHibernateHelper.GetCurrentSession(); 

tx = session.BeginTransaction();
使用(tx)
{
session.CreateSQLQuery(DELETE FROM tb_category WHERE parentID =:parentID)。SetInt64(parentID,pID);

tx.Commit();
}

任何帮助表示赞赏。

解决方案

我认为,您必须执行查询以使其执行某些操作。

您只是创建Query并设置它的参数。

在Hibernate中,运行本机查询的SQLQuery对象有一个.executeUpdate()方法。


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.

解决方案

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.

这篇关于Hibernate NHibernate - 原生SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆