I am new to Dapper, want to know why below is suggested, when my code runs without it?
Ansi Strings and varchar
Dapper supports varchar params, if
The purpose of the example is that it is describing a scenario where the data type is char(10)
. If we just used "abcde"
, Dapper might think that nvarchar(5)
was appropriate. This would be very inefficient in some cases - especially in a where
clause, since the RDBMS can decide that it can't use the index, and instead needs to table scan doing a string conversion for every row in the table from char(10)
to the nvarchar
version. It is for this reason that DbString
exists - to help you control exactly how Dapper configures the parameter for text data.
I think this answers your 1 and 2.
3: are you using ANSI (non-unicode text) or fixed-width text? Note that the ANSI default can also be set globally if you always avoid unicode
4: yes
5: yes
4+5 combined: if you're using nvarchar
: just use string