Commit 7062416c authored by Kevin Pullin's avatar Kevin Pullin

Support a default value for DbString.IsAnsi

It is painful and easy to forget to set `DbString.IsAnsi = true` when
dealing with databases that mainly use char/varchar data types (as
opposed to nchar/nvarchar).

This patch allows a default value for `DbString.IsAnsi` to be configured
via the `DefaultStringDbType` static property.
parent 6950c694
......@@ -2949,10 +2949,34 @@ public T Get<T>(string name)
/// </summary>
sealed partial class DbString
{
static DbString()
{
DefaultStringDbType = DbType.String;
}
private static DbType _defaultStringDbType;
/// <summary>
/// Default value for IsAnsi. Set to either DbType.String (the default) or DbType.AnsiString.
/// </summary>
public static DbType DefaultStringDbType
{
get { return _defaultStringDbType; }
set
{
if (value != DbType.AnsiString && value != DbType.String)
throw new ArgumentException("Invalid value. Must be either DbType.AnsiString or DbType.String");
_defaultStringDbType = value;
}
}
/// <summary>
/// Create a new DbString
/// </summary>
public DbString() { Length = -1; }
public DbString()
{
Length = -1;
IsAnsi = DefaultStringDbType == DbType.AnsiString;
}
/// <summary>
/// Ansi vs Unicode
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment