Can AnsiStrings be used by default with Dapper?

旧城冷巷雨未停 提交于 2019-11-29 01:44:36

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.

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 of DbType.String
  • In the method CreateParamInfoGenerator change the checks on L960, L968, L973 to include DbType.AnsiString as well as DbType.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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!