using (IDbConnection conn = WebDbConn.DbService()) {
conn.Execute(@"
create proc #TestOutputParameterProc @Foo int, @Bar int out as
set @Bar = @Foo select 1 as [A] select 2 as [B]");
try
{
var args = new DynamicParameters(new { Foo = 123 });
args.Add("@Bar", dbType: DbType.Int32,
direction: ParameterDirection.Output);
using (var grids = conn.QueryMultiple("#TestOutputParameterProc",
args, commandType: CommandType.StoredProcedure))
{
// this will fail here; we have not consumed the TDS data yet!
// args.Get<int>("@Bar").IsEqualTo(123);
// note we don't *have* to read the data here; disposing "grids"
// would be enough to skip to the end of the TDS
//var A=grids.Read<int>().Single().Equals(1); // A
//var B=grids.Read<int>().Single().Equals(2); // B
var A = grids.Read<int>().Single(); // A
var B = grids.Read<int>().Single(); // B
}
// at this point we have consumed the TDS data, so the parameter
// values have come back to the caller
args.Get<int>("@Bar").Equals(123);
}
finally
{ // clean up the proc
conn.Execute("drop proc #TestOutputParameterProc");
}
存储过程返回值
http://stackoverflow.com/questions/9870969/can-dapper-return-values-from-a-sql-function/9871380#9871380
http://stackoverflow.com/questions/14723277/dapper-output-parameter-is-not-returning-values/14746522#14746522