mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	解决ClickHouse 批量更新DateTime问题
This commit is contained in:
		@@ -7,6 +7,7 @@ using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using DateTime = System.DateTime;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.ClickHouse.Curd
 | 
			
		||||
{
 | 
			
		||||
@@ -167,6 +168,16 @@ namespace FreeSql.ClickHouse.Curd
 | 
			
		||||
 | 
			
		||||
                                var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
 | 
			
		||||
                                    _commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
 | 
			
		||||
 | 
			
		||||
                                //判断是否是DateTime类型,如果是DateTime类型,需要转换成ClickHouse支持的时间格式
 | 
			
		||||
                                if (col.Attribute.MapType == typeof(DateTime) || col.Attribute.MapType == typeof(DateTime?) )
 | 
			
		||||
                                {
 | 
			
		||||
                                    //获取当前实时区
 | 
			
		||||
                                    var timeZone = TimeZoneInfo.Local;
 | 
			
		||||
 | 
			
		||||
                                    colsql = $"toDateTime({colsql},'Asia/Shanghai')";
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                cwsb.Append(_commonUtils.RewriteColumn(col, colsql));
 | 
			
		||||
                                if (_noneParameter == false)
 | 
			
		||||
                                    _commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user