1

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.

1 Answer 1

3

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 }
Sign up to request clarification or add additional context in comments.

10 Comments

Interesting proposal, but my gut reaction is to be uncomfortable with the idea of an API who's behavior depends on an attribute in the calling assembly. What about performance, inlining and maintainability (specifically the fact that behavior could change by moving a class into a different assembly)?
@Joe il-merge would indeed complicate things
Thanks for response, but stringParam = new DbString { Value = stringVal, IsAnsi = true } is not working. Only when I pass parameters with DynamicParameters it works fine. Could you explan to me how should I use [assembly:SomeName(blah)]?
@MarekRuszczyk to emphasize: that is simply a proposal at this point. For you to use that, I need to write the code. I will check on the dbstring, though - that should work.
@MarekRuszczyk this works fine: pastie.org/9158605 - can you be more specific about the scenario that isn't working?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.