简体   繁体   中英

EntLib 6 and ODP.NET - Accessor loses parameters

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM