I know it’s kind of the wrong thing to do, but I’m dealing with a legacy codebase that has NULLS when it means empty strings and vice versa.
I can’t immediately see how it is possible, but is it possible to get (or modifiy dapper so it will) return an empty string instead of a null string when mapping back from the database.
Dapper doesn’t call any setter when it sees a null, so options might include:
""in the constructornullin the accessorSo:
or:
However, this only applies to reading values; I can’t think of a nice way to get dapper to turn
""intonullwhen passing the dto in as the parameter object; options include:""tonull(perhaps write astring NullIfBlank(this string s)extension method)nullin place of"", and have your database query bind to@NameOrNullrather than@Name