如何执行“ExecuteNonQuery” 在城堡活动记录中

发布于 2024-07-16 19:24:42 字数 528 浏览 8 评论 0原文

我有以下代码通过我们的活动记录 ORM 层执行数据库级别的操作。

public static void Vacuum() {
  Execute(
    delegate(ISession session, object instance) {
      ISQLQuery query =
        session.CreateSQLQuery(@"
          VACUUM billableaddresses;
          ")
      query.List();
      return null;
    }, null);
}

通常,当我需要执行这样的非查询时(我承认这种情况很少见),我简单地输入 select '1'; 在查询之后,它足以安抚 Active Record 来将查询作为非查询执行。

但是,postgres 'vacuum' 命令必须单独运行,并且不能作为多语句查询的一部分。

查看 ISQLQuery 接口,似乎没有执行非查询的方法,所以我想知道如何做到这一点?

I have the following code to perform a database level operation through our active record ORM layer.

public static void Vacuum() {
  Execute(
    delegate(ISession session, object instance) {
      ISQLQuery query =
        session.CreateSQLQuery(@"
          VACUUM billableaddresses;
          ")
      query.List();
      return null;
    }, null);
}

Normally when I need to do a non-query like this (its very rare I admit) I simple put a select '1'; after the query which appeases Active Record enough to execute the query asa nonquery.

However, the postgres 'vacuum' command, must be run on its own and cannot be part of a multi statement query.

looking ISQLQuery interface, there doesnt seem to be a method to execute a nonquery, so I was wondering how this can be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-07-23 19:24:42

对于特定的数据库调用,您可以从中获取原始 IDbConnection

ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof (object)).ConnectionProvider.GetConnection()

For specific DB calls you can get a raw IDbConnection from

ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof (object)).ConnectionProvider.GetConnection()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文