For dapper I need to build support for passing in AnsiString params.
Databases have both unicode and non-unicode strings, picking the right parameter type is sometimes crucial.
DbType.String
vs DbType.AnsiString
for a particular param can heavily effect perf.
In dapper we pass in parameters dynamically, Eg:
Query<User>("select * from Users where Name=@Name", new {Name = "name"});
I have an internal map that says that if I see typeof(String)
I know to pass in the param as a DbType.String
However, I would like my users to be able to denote that the string should be an AnsiString. Attributes are not supported for anonymous classes, so I need a distinct type for this.
Clearly I can invent one:
public class AnsiString
{
private readonly string str;
public AnsiString(string str)
{
this.str = str;
}
public String Value { get { return str; } }
}
Which would give me the clean API:
Query<User>("select * from Users where Name=@Name",
new {Name = new AnsiString("name")});
However, why invent one if such a class exists in System.Data or the BCL.
Is there a type somewhere in the BCL or System.Data
I could use as a container for AnsiString
, with similar semantics to the sample above?