Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

Added support to set a custom parameter prefix (instead of '@')

Open jonataspc opened this issue 3 years ago • 4 comments

Added support for defining a custom parameter prefix (instead of the hard-coded @) for SQL query and parameters collection, separately.

Some providers have problems with @ as a default parameter prefix when used with Dapper, such as Devart dotConnect for MySQL. In that specific case, we have to use : on the SQL query instead (e.g: SELECT foo FROM table WHERE bar=:parameter). With this feature we are able to use Dapper.Contrib on those scenarios.

The configuration was implemented using delegate pattern (same way of GetDatabaseType and TableNameMapper)

Example of use:

SqlMapperExtensions.GetParameterPrefixForQuery = () => ":";
SqlMapperExtensions.GetParameterPrefixForParameterCollection = () => "@";

This PR may also solve/fix: #14 #124 #127

Related topics: https://github.com/DapperLib/Dapper/issues/1296 https://github.com/DapperLib/Dapper/issues/1232

jonataspc avatar Dec 29 '22 02:12 jonataspc

Looks good to me. A much needed one. If I may also request, can the readme/documentation be updated about this feature/custom support? Let me know if i can be of any help in contributing as well. At this point, I am not sure if I have the authority to approve and the contributor process to adhere in.

Sure, documentation was changed to describe the feature.

jonataspc avatar Jan 06 '23 21:01 jonataspc

@jonataspc - This requires a maintainer to give the final approval to merge/approval workflows.

aravindk777 avatar Jan 21 '23 04:01 aravindk777

Does it solve ODBC parameters syntax : ?paramname? ?

Or does it need a parameter suffix to be add ?

Safirion avatar Nov 30 '23 10:11 Safirion

Does it solve ODBC parameters syntax : ?paramname? ?

Or does it need a parameter suffix to be add ?

I think you'll need a parameter suffix to work with ODBC indeed. This PR only adds a custom prefix param.

jonataspc avatar Nov 30 '23 13:11 jonataspc