Open GoogleCodeExporter opened 8 years ago
Did you get a solution, or workaround to this? I'm having a similar issue
inserting numeric values using the iDB2 driver.
Regards,
Original comment by walter.p...@gmail.com
on 25 Sep 2013 at 8:19
Unfortunately no I never found a solution to this problem. I just ended up
doing plain ADO.NET in this case. We've built other applications that use
nhibernate with iDB2 and that works great if you don't mind using a full-on ORM.
Original comment by jonesc...@gmail.com
on 28 Sep 2013 at 3:11
hi,
after a bit of I managed to get this working (we runa also against a as400) you
need to set all parameters as type DbType.Object
I overrode the execute method and then looped over the dynamic parameters added
the required information. this has its draw backs but you get the point
Here is a code snippet. class
public int Execute(string sql, dynamic parameters = null, IDbTransaction transaction = null)
{
var objectParameters = OverrideDapperParameterMapping(parameters);
using (var connection = CreateConnection())
{
return SqlMapper.Execute(connection, sql, objectParameters, transaction, _db2Config.CommandTimeoutSeconds, CommandType.Text);
}
}
private DynamicParameters OverrideDapperParameterMapping(dynamic parameters)
{
if (parameters == null)
return null;
//todo DOES NOT handle a list of a parameters as dapper does need implementing
return CreateDb2CompliantDynamicParameters(parameters);
}
private static DynamicParameters CreateDb2CompliantDynamicParameters(dynamic parameters)
{
var dynamicParameters = new DynamicParameters();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(parameters))
{
dynamicParameters.Add(property.Name.Replace('_', '-'), property.GetValue(parameters), DbType.Object);
}
return dynamicParameters;
}
public IDbConnection CreateConnection()
{
var connection = new iDB2Connection(_db2Config.ConnectionString);
connection.Open();
return connection;
}
Original comment by chocobsm...@gmail.com
on 29 Nov 2013 at 9:31
another method which suits IoC a bit better
//call using
var sql ="select * from something"
var safeParameters = _db2DapperDynamicParameters.ConvertParamters(parameters);
var result = Dapper.SqlMapper.Query(connection, sql, safeParameters);
public interface IDb2DapperDynamicParameters
{
dynamic ConvertParamters(dynamic parameters);
}
public class Db2DapperDynamicParameters : IDb2DapperDynamicParameters
{
public dynamic ConvertParamters(dynamic parameters)
{
if (parameters == null)
return null;
return CreateDb2CompliantDynamicParameters(parameters);
}
private static DynamicParameters CreateDb2CompliantDynamicParameters(dynamic parameters)
{
var dynamicParameters = new DynamicParameters();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(parameters))
{
dynamicParameters.Add(property.Name.Replace('_', '-'), property.GetValue(parameters), DbType.Object);
}
return dynamicParameters;
}
}
Original comment by chocobsm...@gmail.com
on 29 Nov 2013 at 12:54
Original issue reported on code.google.com by
jonesc...@gmail.com
on 7 Jul 2013 at 9:05