我有一个Dapper语句,它返回一个OracleRefCursor:
try
{
using (IDbConnection connection = Connection)
{
var parameters = new OracleDynamicParameters();
parameters.Add("refCursorReturn", null, OracleMappingType.RefCursor, ParameterDirection.Output);
IEnumerable<OracleRefCursor> temp = connection.Query<OracleRefCursor>("MySchema.MyStoredProc", parameters, commandType: CommandType.StoredProcedure);
//I need to convert the OracleRefCursor to an IEnumerable or List of MyObject
return IEnumerable<MyObject>;
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
我在网上找不到任何有关如何将OracleRefCursor转换为我可以使用的任何文档。
答案 0 :(得分:1)
一种方法是(如果可以不使用像OracleRefCursor这样的强类型,那么可以使用:
IEnumerable<dynamic> temp = null;
temp = connection.Query<dynamic>("MySchema.MyStoredProc", parameters, commandType: CommandType.StoredProcedure);
foreach (var dataRow in temp)
{
var fields = dataRow as IDictionary<string, object>;
// do something with fields. (store in datatable, list etc).
}