Login

PetaPoco

PetaPoco is a Micro-ORM released under the Apache License 2.0 by topten software. It's fast, it's easy to use and it's free. I've added stored procedure support, here's how to use it...

If you are using SQL Server and the user you are connecting with has access to system tables, it will pull the procedure definition from the sys.objects and sys.all_parameters tables. If you do not have access or if you are using another provider, you should define the procedure's parameters like so:

PocoProcedureDefinition.DefineProcedure(db, "t_TestProc", new PocoParameterDefinition[] { 
        new PocoParameterDefinition("@In1", DbType.Int32),
        new PocoParameterDefinition("@Out1", DbType.Int32, ParameterDirection.Output),
        new PocoParameterDefinition("@Tax", DbType.Int32, ParameterDirection.InputOutput, precision: 9, scale: 2 ),
        new PocoParameterDefinition("@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue)
    });

The new ExecuteProc method on the Database class takes the procedure name and an object with parameter values. It returns an ExpandoObject with properties for each parameter marked as ReturnValue, Output or InputOutput. It also contains a Rows property which is a list of objects of the specified type just like calling the Query<T> method.

dynamic result = db.ExecuteProc<dynamic>("t_TestProc", new { In1 = 5, Tax = 13.45 });
int returnValue = result.ReturnValue;
decimal Tax = result.Tax;
int count = result.Rows.Count;

Download PetaPoco.cs file with my changes.