Skip to content

Commit 54e1ed6

Browse files
committed
测试并修复Cilckhouse CodeFirst主键问题
1 parent bffc1ac commit 54e1ed6

File tree

4 files changed

+459
-19
lines changed

4 files changed

+459
-19
lines changed

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using FreeSql.DataAnnotations;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace FreeSql.Tests.ClickHouse
11+
{
12+
public class ClickhouseIssueTest
13+
{
14+
private readonly ITestOutputHelper _output;
15+
16+
private static IFreeSql _fsql;
17+
18+
public ClickhouseIssueTest(ITestOutputHelper output)
19+
{
20+
_output = output;
21+
22+
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
23+
"Host=192.168.1.123;Port=8123;Database=test_issue;Compress=True;Min Pool Size=1")
24+
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
25+
.UseNoneCommandParameter(true)
26+
.UseAdoConnectionPool(true)
27+
.Build();
28+
}
29+
30+
#region https: //github.com/dotnetcore/FreeSql/issues/1813
31+
32+
[Fact]
33+
public void TestIssue1813()
34+
{
35+
//var personsUpdate = new List<Person>
36+
//{
37+
// new Person
38+
// {
39+
// Id = 1,
40+
// Name = $"test2{DateTime.Now.Millisecond}",
41+
// Age = 20,
42+
// CreateTime = DateTime.Now
43+
// },
44+
// new Person
45+
// {
46+
// Id = 2,
47+
// Name = "test3"+ 286,
48+
// Age = 22,
49+
// CreateTime = DateTime.Now
50+
// }
51+
//};
52+
53+
//_fsql.Update<Person>().SetSource()
54+
}
55+
56+
[Fact]
57+
public void TestIssue1813CodeFirst()
58+
{
59+
_fsql.CodeFirst.SyncStructure<Person>();
60+
var insertSingle = _fsql.Insert(new Person
61+
{
62+
Name = $"test{DateTime.Now.Millisecond}",
63+
Age = 18,
64+
CreateTime = DateTime.Now
65+
}).ExecuteAffrows();
66+
67+
_output.WriteLine(insertSingle.ToString());
68+
69+
var persons = new List<Person>
70+
{
71+
new Person
72+
{
73+
Name = $"test2{DateTime.Now.Millisecond}",
74+
Age = 20,
75+
CreateTime = DateTime.Now
76+
},
77+
new Person
78+
{
79+
Name = "test3" + 286,
80+
Age = 22,
81+
CreateTime = DateTime.Now
82+
}
83+
};
84+
85+
var insertMany = _fsql.Insert(persons).ExecuteAffrows();
86+
}
87+
[Fact]
88+
public void TestIssue1813CodeFirst2()
89+
{
90+
_fsql.CodeFirst.SyncStructure<Person>();
91+
var insertSingle = _fsql.Insert(new Person
92+
{
93+
Id = Guid.NewGuid().ToString(),
94+
Name = $"test{DateTime.Now.Millisecond}",
95+
Age = 18,
96+
CreateTime = DateTime.Now
97+
}).ExecuteAffrows();
98+
99+
_output.WriteLine(insertSingle.ToString());
100+
101+
var persons = new List<Person>
102+
{
103+
new Person
104+
{
105+
Id = Guid.NewGuid().ToString(),
106+
Name = $"test2{DateTime.Now.Millisecond}",
107+
Age = 20,
108+
CreateTime = DateTime.Now
109+
},
110+
new Person
111+
{
112+
Id = Guid.NewGuid().ToString(),
113+
Name = "test3" + 286,
114+
Age = 22,
115+
CreateTime = DateTime.Now
116+
}
117+
};
118+
119+
var insertMany = _fsql.Insert(persons).ExecuteAffrows();
120+
}
121+
122+
123+
124+
public class Person
125+
{
126+
[Column(IsPrimary = true, IsIdentity = true)]
127+
public string Id { get; set; }
128+
public string Name { get; set; }
129+
public int Age { get; set; }
130+
public DateTime CreateTime { get; set; }
131+
public DateTime? UpdateTime { get; set; }
132+
}
133+
134+
#endregion
135+
}
136+
}

0 commit comments

Comments
 (0)