Add support for DefaultTypeMap.MatchNamesWithUnderscores #171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Re #2
I needed support for
DefaultTypeMap.MatchNamesWithUnderscores
in a project I was working on. I've created a minimal implementation and added passing unit tests. I don't believe it will break anything that was previously working,There was a previous pull request for this in 2016 (DapperLib/Dapper#605) which was closed either because some of the AppendColumnNameEqualsValue methods may have been missed, or because there was a plan for something more general. In particular it looks like Column attributes were on the horizon (DapperLib/Dapper#722).
Essentially I've added a small method to wrap access to the property name:
and replaced references to column name with references to this method. Eg:
become
Were Column attributes to come into play, I'd imagine they would take precedence over direct access to the property name, so would equally take precdence over calls to ColumnMapping.ColumnName.
The Pascal to Snake Case method uses the following logic:
This will probably create unexpected results where acronyms are used in property names (eg the PersonID proprty would map to a person_i_d column), but I don't think there is any logical way around that.
Apologies if I've missed anything.