我正在做一个MVC应用程序。我正在使用带有Enterprise Library连接的Oracle数据库。
我遇到的问题是在使用ExecuteSprocAccessor
...
当我使用Linq
绑定返回的数据时,它工作正常。但是当我ExecuteSprocAccessor
收到错误时..... The number of parameters does not match number of values for stored procedure
Database db = readConfig.ReadWebConfig();
string SP_NAME = "PKG_AR_PRESUPUESTOS_HS.GET_CAMPANAS";
using (DbCommand dbCommand = db.GetStoredProcCommand(SP_NAME))
{
dbCommand.Parameters.Clear();
db.AddInParameter(dbCommand, "p_COD_PAIS", DbType.Int32, 32);
db.AddInParameter(dbCommand, "p_COD_COMPANIA", DbType.Int32, 36);
db.AddInParameter(dbCommand, "p_COD_MEDIO", DbType.Int32, 4);
db.AddInParameter(dbCommand, "p_COD_CLIENTE", DbType.Int32, 285);
OracleParameter oraPara1 = new OracleParameter("CURSORSALIDA", OracleType.Cursor);
oraPara1.Direction = ParameterDirection.Output;
dbCommand.Parameters.Add(oraPara1);
List<Campana> result2 = db.ExecuteDataSet(dbCommand).Tables[0].AsEnumerable().ToList().ConvertAll(dr => new Campana
{
COD_CAMPANA = Convert.ToInt32(dr["COD_CAMPANA"].ToString()),
COD_COMPANIA = Convert.ToInt32(dr["COD_COMPANIA"].ToString()),
COD_PRODUCTO = Convert.ToInt32(dr["COD_PRODUCTO"].ToString()),
DES_CAMPANA = dr["DES_CAMPANA"].ToString()
});
&#13;
这项工作很好......
但是当我使用
时
Database db = readConfig.ReadWebConfig();
string SP_NAME = "PKG_AR_PRESUPUESTOS_HS.GET_CAMPANAS";
using (DbCommand dbCommand = db.GetStoredProcCommand(SP_NAME))
{
dbCommand.Parameters.Clear();
db.AddInParameter(dbCommand, "p_COD_PAIS", DbType.Int32, 32);
db.AddInParameter(dbCommand, "p_COD_COMPANIA", DbType.Int32, 36);
db.AddInParameter(dbCommand, "p_COD_MEDIO", DbType.Int32, 4);
db.AddInParameter(dbCommand, "p_COD_CLIENTE", DbType.Int32, 285);
OracleParameter oraPara1 = new OracleParameter("CURSORSALIDA", OracleType.Cursor);
oraPara1.Direction = ParameterDirection.Output;
dbCommand.Parameters.Add(oraPara1);
List<Campana> result = db.ExecuteSprocAccessor<Campana>(SP_NAME, dbCommand.Parameters).ToList<Campana>();
&#13;
收到错误... The number of parameters does not match number of values for stored procedure
即使我使用Mapping
IRowMapper<Campana> resmapper = MapBuilder<Campana>.MapAllProperties()
.Map(x => x.COD_CAMPANA).ToColumn("COD_CAMPANA")
.Map(x => x.COD_COMPANIA).ToColumn("COD_COMPANIA")
.Map(x => x.DES_CAMPANA).ToColumn("DES_CAMPANA")
.Map(x => x.COD_PRODUCTO).ToColumn("COD_PRODUCTO")
.Build();
DataTable dt = db.ExecuteDataSet(dbCommand).Tables[0];
List<Campana> result = db.ExecuteSprocAccessor<Campana>(SP_NAME, resmapper, dbCommand.Parameters).ToList<Campana>();
&#13;
我得到了同样的错误......
ExecuteSprocAccessor
有什么问题?
无论如何,我的Campana课程看起来像这样。
public class Campana
{
public Int32 COD_COMPANIA { get; set; }
public Int32 COD_CAMPANA { get; set; }
public string DES_CAMPANA { get; set; }
public Int32 COD_PRODUCTO { get; set; }
}
&#13;
答案 0 :(得分:0)
我解决了它传递一个对象[]而不是cmd.Parameters
object[] param = ParametertoObj(dbCommand);
List<Campana> result = db.ExecuteSprocAccessor<Campana>(SP_NAME, resmapper, param).ToList<Campana>();
&#13;
和我创建数组的类
public object[] ParametertoObj(DbCommand cmd)
{
object[] obj = new object[cmd.Parameters.Count];
int i = 0;
foreach (DbParameter item in cmd.Parameters)
{
obj[i] = item.Value;
i++;
}
return obj;
}
&#13;