Can AnsiStrings be used by default with Dapper?
To use ansistrings by default I had to (referring to Dapper 1.3 source from NuGet):
- Alter the type map to use
DbType.AnsiString
on L164 instead ofDbType.String
- In the method
CreateParamInfoGenerator
change the checks on L960, L968, L973 to includeDbType.AnsiString
as well asDbType.String
.
The problem with the invalid IL seemed to be that the later branch of the code on L1000 checks for typeof(string)
whereas the preceeding branches use DbType
.
Doing that everything is peachy again - no more index scans!
You can accomplish this without modifying the source code.
Dapper.SqlMapper.AddTypeMap(typeof(string), System.Data.DbType.AnsiString);
Setting this once will adjust all of your strings to varchar.