Dapper 返回存储过程值

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("@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().Single().Equals(1); // A
//var B=grids.Read().Single().Equals(2); // B
var A = grids.Read().Single(); // A
var B = grids.Read().Single(); // B

}
// at this point we have consumed the TDS data, so the parameter
// values have come back to the caller
args.Get("@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

转载于:https://www.cnblogs.com/ggbbeyou/archive/2013/03/13/2957645.html

你可能感兴趣的:(Dapper 返回存储过程值)