- 优化 TypeHandlers 支持 DateTime 映射规则;#1634

This commit is contained in:
2881099
2023-10-10 02:07:29 +08:00
parent 1f3f60f6fa
commit 58f261b5e5
30 changed files with 288 additions and 28 deletions

View File

@ -100,8 +100,16 @@ namespace FreeSql.GBase
var ts = (TimeSpan)value;
return $"interval({ts.Days} {ts.Hours}:{ts.Minutes}:{ts.Seconds}.{ts.Milliseconds}) day(9) to fraction";
}
if (type == typeof(DateTime) || type == typeof(DateTime?))
if (type == typeof(DateTime))
{
if (Utils.TypeHandlers.TryGetValue(typeof(DateTime), out var typeHandler)) return typeHandler.Serialize(value)?.ToString();
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 (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"), "'");