Dapper mapping String parameter as AnsiString

ado c# dapper interbase

Question

I need to pass parameters to SQL statement, with Firebird ADO everything works well, but with InterBase ADO there is a problem. My code:

result = conn.Query<DestClass>(sqlCmd, new
{
  stringParam = stringVal,
  intParam1 = intVal1,
  intParam2 = intVal2
}).Single();

With that I've got FormatException, but when I define parameters with DynamicParameters and setting DbType.AnsiString for stringParam, SQL works well. But I've got many places in my code when I need to pass string and I don't want to change this in all places.

Then I found that I can use Dapper.SqlMapper.AddTypeMap(typeof(String), DbType.AnsiString); but I can't. I've got Common Language Runtime detected an invalid program.

How to resolve this issue?

EDIT

It looks like problem is solved in Dapper v1.22.

Expert Answer

There is a proposal to add an assembly-level attribute of the form:

[assembly:SomeName(blah)]

that would control the default string type for all types coming from that assembly. This would probably achieve most of what you need (although it would push the swing the other way, so you need to tell the other uses what to do). I am currently very actively hacking dapper, so I would expect this to materialize in the short term.

Note that you do not need to use DynamicParameters; you can also use:

stringParam = new DbString { Value = stringVal, IsAnsi = true }


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why