good How do you execute a stored procedure using Castle ActiveRecord? a good career (3)

I believe there is a discussion on this very topic somewhere on the net but I lost the url and I am unable to find it via googling.

What I might try right now would be:

ISessionFactoryHolder factoryHolder = ActiveRecordMediator<EntityClass>.GetSessionFactoryHolder();
ISession session = factoryHolder.CreateSession(typeof(EntityClass));
    IDbCommand cmd = session.Connection.CreateCommand();
    cmd.CommandText = "spName";
catch(Exception ex)


However, I am not quite sure if this is the correct way to do this or if perhaps a better way exists.

Answer #2

You can also get an IDbConnection with:


Answer #3

This works for me (stored procedure with params and dynamic result table):

// get Connection
System.Data.IDbConnection con = ActiveRecordMediator.GetSessionFactoryHolder()

// set Command
System.Data.IDbCommand cmd = con.CreateCommand();
cmd.CommandText = "name_of_stored_procedure";
cmd.CommandType = System.Data.CommandType.StoredProcedure;

// set Parameter of Stored Procedure
System.Data.SqlClient.SqlParameter param = new System.Data.SqlClient.SqlParameter("@parameter_name", System.Data.SqlDbType.NVarChar);
param.Value = "value_of_parameter";

// call Stored Procedure (without getting result)

// ... or read results
System.Data.SqlClient.SqlDataReader r = (System.Data.SqlClientSqlDataReader)cmd.ExecuteReader();
while(r.Read()) {
    System.Console.WriteLine("result first col: " + r.GetString(0));