- 优化 TypeHandlers 支持 Enum 枚举映射规则;#1634

This commit is contained in:
2881099
2024-02-08 13:06:43 +08:00
parent 91362ad07a
commit 53443dc22b
34 changed files with 120 additions and 529 deletions

View File

@ -102,14 +102,14 @@ namespace FreeSql.GBase
}
if (type == typeof(DateTime))
{
if (Utils.TypeHandlers.TryGetValue(typeof(DateTime), out var typeHandler)) return typeHandler.Serialize(value)?.ToString();
if (Utils.TypeHandlers.TryGetValue(typeof(DateTime), out var typeHandler)) return FormatSql("{0}", typeHandler.Serialize(value), 1);
if (col?.DbPrecision > 0)
return string.Concat("'", ((DateTime)value).ToString($"yyyy-MM-dd HH:mm:ss.{"f".PadRight(col.DbPrecision, 'f')}"), "'");
return string.Concat("'", ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"), "'");
}
if (type == typeof(DateTime?))
{
if (Utils.TypeHandlers.TryGetValue(typeof(DateTime?), out var typeHandler)) return typeHandler.Serialize(value)?.ToString();
if (Utils.TypeHandlers.TryGetValue(typeof(DateTime?), out var typeHandler)) return FormatSql("{0}", typeHandler.Serialize(value), 1);
if (col?.DbPrecision > 0)
return string.Concat("'", ((DateTime)value).ToString($"yyyy-MM-dd HH:mm:ss.{"f".PadRight(col.DbPrecision, 'f')}"), "'");
return string.Concat("'", ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"), "'");