简体   繁体   中英

Call Oracle Stored Procedure and Package with Enterprise Library

I'm creating an ASP.NET MVC application, and I am using Enterprise Library to connect to my Oracle database.

I always used SQL Server before, and this is the way I used to call it.

Database db = readConfig.ReadWebConfig();
SP_NAME = "Get_Data";

using (DbCommand dbCommand = db.GetStoredProcCommand(SP_NAME))
{
    //Pass parameters
    dbCommand.Parameters.Clear();
    db.AddInParameter(dbCommand, "CommParent_ID", DbType.Int32, comment.CommParent_id);
    db.AddInParameter(dbCommand, "Type_ID", DbType.Int32, comment.Type_id);

    IRowMapper<CommentEntity> resmapper = MapBuilder<CommentEntity>.MapAllProperties()
                                                  .Map(x => x.UserEmail).ToColumn("Email")
                                                  .Map(x => x.Nick).ToColumn("FullName")
                                                  .Map(x => x.User_id).ToColumn("User_ID")
                                                  .Map(x => x.Comment_id).ToColumn("Comment_ID")
                                                  .Build();

    List<CommentEntity> result = db.ExecuteSprocAccessor<CommentEntity>(SP_NAME, resmapper, dbCommand.Parameters).ToList<CommentEntity>();
}

The problem I have using Oracle is that the stored procedure is embedded in a package and package body.

My question is, how I set package name in my call.

Thanks

Change your stored procedure name to:

SP_NAME = "package_name.Get_Data";

To add a SYS_REFCURSOR out parameter use this:

OracleParameter oraP = new OracleParameter();
oraP.OracleDbType = OracleDbType.RefCursor;
oraP.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(oraP);

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