Skip to content

Commit 989cf29

Browse files
committed
测试ClickHouse 批量更新DateTime问题
1 parent 9aef33e commit 989cf29

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickhouseIssueTest.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ClickhouseIssueTest(ITestOutputHelper output)
2222
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
2323
"Host=192.168.1.123;Port=8123;Database=test_issue;Compress=True;Min Pool Size=1")
2424
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
25-
.UseNoneCommandParameter(false)
25+
.UseNoneCommandParameter(true)
2626
.UseAdoConnectionPool(true)
2727
.Build();
2828
}
@@ -45,22 +45,25 @@ public void TestIssue1813()
4545
{
4646
Id = "9cd7af52-85cc-4d26-898a-4020cadb0491",
4747
Name = "update_name1",
48-
UpdateTime = DateTime.Now
48+
UpdateTime = DateTime.Now,
49+
CreateTime = DateTime.Parse("2024-05-30 10:01:02")
4950
});
5051

5152
updatePerson.Add(new Person
5253
{
5354
Id = "bd9f9ed6-bd03-4675-abb4-12b7fdac7678",
5455
Name = "update_name2",
55-
UpdateTime = DateTime.Now
56+
UpdateTime = DateTime.Now,
57+
CreateTime = DateTime.Parse("2024-05-30 10:01:02")
5658
});
5759

58-
_fsql.Update<Person>().SetSource(updatePerson).UpdateColumns(person => new
59-
{
60-
person.Name,
61-
person.UpdateTime,
62-
}).ExecuteAffrows();
63-
60+
var sql = _fsql.Update<Person>().SetSource(updatePerson)
61+
.UpdateColumns(person => new
62+
{
63+
person.Name,
64+
person.UpdateTime,
65+
person.CreateTime
66+
}).ToSql();
6467
}
6568

6669
[Fact]
@@ -94,6 +97,7 @@ public void TestIssue1813CodeFirst()
9497

9598
var insertMany = _fsql.Insert(persons).ExecuteAffrows();
9699
}
100+
97101
[Fact]
98102
public void TestIssue1813CodeFirst2()
99103
{
@@ -130,11 +134,11 @@ public void TestIssue1813CodeFirst2()
130134
}
131135

132136

133-
134137
public class Person
135138
{
136139
[Column(IsPrimary = true, IsIdentity = true)]
137140
public string Id { get; set; }
141+
138142
public string Name { get; set; }
139143
public int Age { get; set; }
140144
public DateTime CreateTime { get; set; }

Providers/FreeSql.Provider.ClickHouse/Curd/ClickHouseUpdate.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ public override void ToSqlExtension110(StringBuilder sb, bool isAsTableSplited)
173173
if (col.Attribute.MapType == typeof(DateTime) || col.Attribute.MapType == typeof(DateTime?) )
174174
{
175175
//获取当前实时区
176-
var timeZone = TimeZoneInfo.Local;
177-
178176
colsql = $"toDateTime({colsql},'Asia/Shanghai')";
179177
}
180178

0 commit comments

Comments
 (0)