mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 优化 TypeHandlers 支持 DateTime 映射规则;#1634
This commit is contained in:
@ -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"), "'");
|
||||
|
Reference in New Issue
Block a user