Reputation: 1
I'm sure I can't be the first one trying to use EntLib 6's Accessors to execute an Oracle SP with parameters. It all worked fine and dandy when I was using the (deprecated) OracleClient from MS, but when I switched to Oracle's own ODP.NET (using EntLibContrib 6) I started getting the infamous "wrong number or types of arguments in call to 'TEST_PROCEDURE'".
Here's my code:
Main
var query = "TEST_PROCEDURE";
var accessor = _db.CreateSprocAccessor(
query,
new OracleParamMapper(),
new ColumnMapper<MyEntity>().Map()
);
var p1 = new OracleParameter("param1", OracleDbType.Varchar2, 1);
p1.Direction = ParameterDirection.Input;
p1.Value = "T";
var p2 = new OracleParameter("param2", OracleDbType.RefCursor);
p2.Direction = ParameterDirection.Output;
return accessor.Execute(p1, p2);
OracleParamMapper
public class OracleParamMapper : IParameterMapper
{
public void AssignParameters(DbCommand command, object[] parameterValues)
{
((OracleCommand)command).BindByName = true;
foreach (var item in parameterValues)
{
command.Parameters.Add(item);
}
}
}
This mapper gets invoked, and I can see the parameters being correctly added to the collection, but then for some misterious reason they seem to disappear when the call to Execute is made.
Stored Procedure
PROCEDURE TEST_PROCEDURE (param1 IN VARCHAR2, param2 IN OUT SYS_REFCURSOR);
Has anyone been able to make this work? Thanks in advance.
Upvotes: 0
Views: 77
Reputation: 1
Well, it's working now. In fact the answer was right there this whole time. All I had to do was to use the classes provided by the EntLibContrib library and voila!
In case anyone reads this, just take a look at the CreateOracleSprocAccessor()
method in the EntLibContrib.Data.OdpNet.OracleDatabase
class. Cheers!
Upvotes: 0