zoukankan      html  css  js  c++  java
  • 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<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

  • 相关阅读:
    C#中任意类型数据转成JSON格式
    数据库用户映射到SQL Server登录名
    浅述WinForm多线程编程与Control.Invoke的应用
    Git错误一例
    提高VS2010/VS2012编译速度
    给有兴趣、有责任要讲课、分享的朋友推荐两本书
    中国剩余定理
    中国剩余定理
    洛谷1546 最短网路
    洛谷1111 修复公路
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/2957645.html
Copyright © 2011-2022 走看看