Is there a way to call a stored procedure with Dapper?

In the simple case you can do: var user = cnn.Query<User>(“spGetUser”, new {Id = 1}, commandType: CommandType.StoredProcedure).First(); If you want something more fancy, you can do: var p = new DynamicParameters(); p.Add(“@a”, 11); p.Add(“@b”, dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add(“@c”, dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); cnn.Execute(“spMagicProc”, p, commandType: CommandType.StoredProcedure); int b = p.Get<int>(“@b”); int c = p.Get<int>(“@c”); … Read more

How to set value of composite variable field using dynamic SQL

Faster with hstore Since Postgres 9.0, with the additional module hstore installed in your database there is a very simple and fast solution with the #= operator that … replace[s] fields in record with matching values from hstore. To install the module: CREATE EXTENSION hstore; Examples: SELECT my_record #= ‘”field”=>”value”‘::hstore; — with string literal SELECT … Read more

How to assign an exec result to a sql variable?

I always use the return value to pass back error status. If you need to pass back one value I’d use an output parameter. sample stored procedure, with an OUTPUT parameter: CREATE PROCEDURE YourStoredProcedure ( @Param1 int ,@Param2 varchar(5) ,@Param3 datetime OUTPUT ) AS IF ISNULL(@Param1,0)>5 BEGIN SET @Param3=GETDATE() END ELSE BEGIN SET @Param3=’1/1/2010′ END … Read more