Commit 6ef748ab authored by Sebastian Burgstaller's avatar Sebastian Burgstaller

Added possibility to add custom type maps - enables serialization of enums to...

Added possibility to add custom type maps - enables serialization of enums to DbType.String instead of DbType.Int32
parent 963b6e71
...@@ -410,13 +410,18 @@ static SqlMapper() ...@@ -410,13 +410,18 @@ static SqlMapper()
typeMap[typeof(Object)] = DbType.Object; typeMap[typeof(Object)] = DbType.Object;
} }
public static void AddTypeMap(Type type, DbType dbType)
{
typeMap[type] = dbType;
}
internal const string LinqBinary = "System.Data.Linq.Binary"; internal const string LinqBinary = "System.Data.Linq.Binary";
internal static DbType LookupDbType(Type type, string name) internal static DbType LookupDbType(Type type, string name)
{ {
DbType dbType; DbType dbType;
var nullUnderlyingType = Nullable.GetUnderlyingType(type); var nullUnderlyingType = Nullable.GetUnderlyingType(type);
if (nullUnderlyingType != null) type = nullUnderlyingType; if (nullUnderlyingType != null) type = nullUnderlyingType;
if (type.IsEnum) if (type.IsEnum && !typeMap.ContainsKey(type))
{ {
type = Enum.GetUnderlyingType(type); type = Enum.GetUnderlyingType(type);
} }
......
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