igor-tkachev/bltoolkit — pull request #133 by jasonf20 (2012-12-22 14:23:28+00:00)
Title: Added support for using oracle sys_refcursor as an output parameter of stored procedure calls generated from an abstract DataAccessor

Hi,

I have added support for using sys_refcursor objects as output parametes of stored procedures in generated DataAccessors and mapping them to an object representing that refcursor.

This is currently supported by my commit only in Oracle, but can easily made available in any DataProvider which supports refcursors.

Here is an example of what is possible with this feature:
NOTE: The reason I use generic parameters in Method1() is because I generate the abstract class from the DB and have no way of telling what the actual type is so I let the user provide it. This would work without generic parameters as well.

using System;
using BLToolkit.Data;
using BLToolkit.Data.DataProvider;
using BLToolkit.DataAccess;
using BLToolkit.TypeBuilder;

namespace BLToolkitTest
{

// Procedure:
/*
* procedure Method1 (myNumber NUMBER, myObject sys_refcursor, myObject2 sys_refcursor) is
* BEGIN
* open myObject for select myNumber + 1 as MyNumber from dual;
* open myObject2 for select myNumber + 2 as MyNumber from dual;
* END;
*/

class Program
{
static void Main(string[] args)
{
DbManager.AddDataProvider(new OdpDataProvider());
TypeFactory.SaveTypes = true;
MyDataAccessor dataAccessor = DataAccessor.CreateInstance();
MyObject outValue1;
MyObject outValue2;
dataAccessor.Method1(1, out outValue1, out outValue2);
Console.WriteLine(outValue1.MyNumber);
Console.WriteLine(outValue2.MyNumber);

// Output:
// 2
// 3
}
}

public abstract class MyDataAccessor : DataAccessor
{
[SprocName("Database.Method1")]
public abstract void Method1(int myNumber, [Direction.Output] [RefCursor] out T1 myObject, [Direction.Output] [RefCursor] out T2 myObject2);

protected override DbManager CreateDbManager()
{
return new DbManager("MyConnection");
}
}

public class MyObject
{
public int MyNumber { get; set; }
}

}