Although Castle ActiveRecord handles the majority, if not all, of your data persistence requirements, there is often a need to get access to the underlying database connection for tasks like bulk SQL copies, one-off stored procedure calls, etc.
This snippet of code demonstrates getting the connection and calling a stored procedure:
using (ISession session = ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof(ActiveRecordBase)))
{
using (IDbCommand command = session.Connection.CreateCommand())
{
command.CommandText = "up_DoStuff";
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 300;
command.ExecuteNonQuery();
command.Connection.Close();
}
session.Close();
}
That's it.