views:

270

answers:

1

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?

+1  A: 

For specific DB calls you can get a raw IDbConnection from

ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof (object)).ConnectionProvider.GetConnection()
Mauricio Scheffer
Awesome. This is exactly what I was after, thanks.
Ash
ActiveRecord FAQ: http://using.castleproject.org/display/AR/FAQ
Mauricio Scheffer