在Dapper中使用DataReader和Oracle

时间:2013-06-04 14:07:12

标签: dapper

如何获取值读取值,使用DataReader读取以下代码中的multi返回的字段值,以设置Class中的值

OracleRefCursor m_Cursor=null;
Dapper.SqlMapper.GridReader multi =null;

using (m_Conn = new OracleConnection(m_ConnectionString))
{ 
     try
     {
          m_Conn.Open();
          String m_LastName = "S" + "%";
          String m_Id = "";
          String m_EmpId = "";

          var p = new OracleDynamicParameters();

          p.Add(":p_LastName", m_LastName);
          p.Add(":p_Id", m_Id);
          p.Add(":p_EmpId", m_EmpId);                   
          p.Add( ":p_Cursor1", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output );


          using (multi = m_Conn.QueryMultiple(m_ProcedureName, param: p, commandType: CommandType.StoredProcedure))
          {                           

          }
    }
    catch (Exception ex)
    {
           String m_Error = ex.ToString();
    }

}//end of using statement

1 个答案:

答案 0 :(得分:0)

来自Dapper docs

var sql = 
@"
select * from Customers where CustomerId = @id
select * from Orders where CustomerId = @id
select * from Returns where CustomerId = @id";

using (var multi = connection.QueryMultiple(sql, new {id=selectedId}))
{
   var customer = multi.Read<Customer>().Single();
   var orders = multi.Read<Order>().ToList();
   var returns = multi.Read<Return>().ToList();
   ...
}