Why does Dapper remove prefix characters when creating a command?

I call the stored procedure in Sybase ASE using the provider "ASEOLEDB.1".

SP takes one varchar (255) argument, called @PricePreference, which defaults to NULL in SP.

I use the Dapper QueryMultiple method and pass in a DynamicParameters object:

var parameters = new DynamicParameters();
parameters.Add("@PricePreference", "Foo");
var reader = dbConnection.QueryMultiple("myProcName", parameters, commandType: CommandType.StoredProcedure);

This code behaves as if I didn't pass the parameter at all. This is apparently due to the fact that the AddParameters () method in the Dapper DynamicParameters class calls Clean () for my parameter name, which removes the '@' prefix (or the equivalent for other DBMSs) - see โ€œWorking with Parameter Keepersโ€ on MSDN is here ).

Without the '@' prefix, Sybase cannot match the argument.

Conversely, when I comment on the Clean () call, I get the correct result from the query.

What is the point of removing the '@' prefix?

+4
source share
1 answer

In short: it simplifies a lot of code and checks if we need to worry about just one scenario. In every other DBMS: it works equally well with and without - and, of course, when you specify the parameter names through the properties of the object, they are: without - so this was the obvious way for you. If this does not work with a specific RDBMS, Iโ€™m sure that we can explore ways to fix it. Presumably just trusting DynamicParameters and not reading them.

+1
source

All Articles