Skip to content

Commit b04a4e7

Browse files
2881028810
authored andcommitted
- 修复 Insert ClearData 重复利用的 bug(使用 IgnoreColumns 进行大批量插入时会发生);
1 parent 250d13c commit b04a4e7

File tree

28 files changed

+116
-44
lines changed

28 files changed

+116
-44
lines changed

Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
5-
<Version>0.7.3</Version>
5+
<Version>0.7.4</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>YeXiangQin</Authors>
88
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>

FreeSql.DbContext/FreeSql.DbContext.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
5-
<Version>0.7.3</Version>
5+
<Version>0.7.4</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>YeXiangQin</Authors>
88
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

FreeSql.Repository/FreeSql.Repository.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
5-
<Version>0.7.3</Version>
5+
<Version>0.7.4</Version>
66
<Authors>YeXiangQin</Authors>
77
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
88
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>

FreeSql.Tests/FreeSql.Tests.Provider.MySqlConnector/MySqlConnector/Curd/MySqlInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ public void IgnoreColumns()
7777

7878
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
7979
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`) VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
80+
81+
g.mysql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
82+
var itemsIgnore = new List<TopicIgnore>();
83+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
84+
g.mysql.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
85+
Assert.Equal(2072, itemsIgnore.Count);
86+
Assert.Equal(2072, g.mysql.Select<TopicIgnore>().Where(a => a.Title == null).Count());
87+
}
88+
[Table(Name = "tb_topicIgnoreColumns")]
89+
class TopicIgnore
90+
{
91+
[Column(IsIdentity = true, IsPrimary = true)]
92+
public int Id { get; set; }
93+
public int Clicks { get; set; }
94+
public string Title { get; set; }
95+
public DateTime CreateTime { get; set; }
8096
}
8197
[Fact]
8298
public void ExecuteAffrows()

FreeSql.Tests/FreeSql.Tests/MySql/Curd/MySqlInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ public void IgnoreColumns()
7878

7979
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
8080
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`) VALUES(?Clicks_0), (?Clicks_1), (?Clicks_2), (?Clicks_3), (?Clicks_4), (?Clicks_5), (?Clicks_6), (?Clicks_7), (?Clicks_8), (?Clicks_9)", sql);
81+
82+
g.mysql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
83+
var itemsIgnore = new List<TopicIgnore>();
84+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
85+
g.mysql.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
86+
Assert.Equal(2072, itemsIgnore.Count);
87+
Assert.Equal(2072, g.mysql.Select<TopicIgnore>().Where(a => a.Title == null).Count());
88+
}
89+
[Table(Name = "tb_topicIgnoreColumns")]
90+
class TopicIgnore
91+
{
92+
[Column(IsIdentity = true, IsPrimary = true)]
93+
public int Id { get; set; }
94+
public int Clicks { get; set; }
95+
public string Title { get; set; }
96+
public DateTime CreateTime { get; set; }
8197
}
8298
[Fact]
8399
public void ExecuteAffrows()

FreeSql.Tests/FreeSql.Tests/Oracle/Curd/OracleInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ public void IgnoreColumns()
152152
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(:Clicks_9)
153153
SELECT 1 FROM DUAL", sql);
154154
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
155+
156+
g.oracle.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
157+
var itemsIgnore = new List<TopicIgnore>();
158+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
159+
g.oracle.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
160+
Assert.Equal(2072, itemsIgnore.Count);
161+
Assert.Equal(2072, g.oracle.Select<TopicIgnore>().Where(a => a.Title == null).Count());
162+
}
163+
[Table(Name = "tb_topicICs")]
164+
class TopicIgnore
165+
{
166+
[Column(IsIdentity = true, IsPrimary = true)]
167+
public int Id { get; set; }
168+
public int Clicks { get; set; }
169+
public string Title { get; set; }
170+
public DateTime CreateTime { get; set; }
155171
}
156172
[Fact]
157173
public void ExecuteAffrows()

FreeSql.Tests/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ public void IgnoreColumns()
6464

6565
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
6666
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\") VALUES(@clicks_0), (@clicks_1), (@clicks_2), (@clicks_3), (@clicks_4), (@clicks_5), (@clicks_6), (@clicks_7), (@clicks_8), (@clicks_9)", sql);
67+
68+
g.pgsql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
69+
var itemsIgnore = new List<TopicIgnore>();
70+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
71+
g.pgsql.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
72+
Assert.Equal(2072, itemsIgnore.Count);
73+
Assert.Equal(2072, g.pgsql.Select<TopicIgnore>().Where(a => a.Title == null).Count());
74+
}
75+
[Table(Name = "tb_topicIgnoreColumns")]
76+
class TopicIgnore
77+
{
78+
[Column(IsIdentity = true, IsPrimary = true)]
79+
public int Id { get; set; }
80+
public int Clicks { get; set; }
81+
public string Title { get; set; }
82+
public DateTime CreateTime { get; set; }
6783
}
6884
[Fact]
6985
public void ExecuteAffrows()

FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ public void IgnoreColumns()
7373

7474
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime, a.TypeGuid }).ToSql();
7575
Assert.Equal("INSERT INTO [tb_topic]([Clicks]) VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
76+
77+
_sqlserverFixture.SqlServer.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
78+
var itemsIgnore = new List<TopicIgnore>();
79+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
80+
_sqlserverFixture.SqlServer.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
81+
Assert.Equal(2072, itemsIgnore.Count);
82+
Assert.Equal(2072, _sqlserverFixture.SqlServer.Select<TopicIgnore>().Where(a => a.Title == null).Count());
83+
}
84+
[Table(Name = "tb_topicIgnoreColumns")]
85+
class TopicIgnore
86+
{
87+
[Column(IsIdentity = true, IsPrimary = true)]
88+
public int Id { get; set; }
89+
public int Clicks { get; set; }
90+
public string Title { get; set; }
91+
public DateTime CreateTime { get; set; }
7692
}
7793
[Fact]
7894
public void ExecuteAffrows()

FreeSql.Tests/FreeSql.Tests/SqlServer/SqlServerExpression/ConvertTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public void ToDouble()
9292
public void ToInt16()
9393
{
9494
var data = new List<object>();
95-
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
96-
data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
95+
//data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
96+
//data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
9797
}
9898
[Fact]
9999
public void ToInt32()
@@ -135,8 +135,8 @@ public void this_ToString()
135135
public void ToUInt16()
136136
{
137137
var data = new List<object>();
138-
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
139-
data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
138+
//data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
139+
//data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
140140
}
141141
[Fact]
142142
public void ToUInt32()

FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteInsertTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ public void IgnoreColumns()
6464

6565
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
6666
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\") VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
67+
68+
g.sqlite.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
69+
var itemsIgnore = new List<TopicIgnore>();
70+
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
71+
g.sqlite.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
72+
Assert.Equal(2072, itemsIgnore.Count);
73+
Assert.Equal(2072, g.sqlite.Select<TopicIgnore>().Where(a => a.Title == null).Count());
74+
}
75+
[Table(Name = "tb_topicIgnoreColumns")]
76+
class TopicIgnore
77+
{
78+
[Column(IsIdentity = true, IsPrimary = true)]
79+
public int Id { get; set; }
80+
public int Clicks { get; set; }
81+
public string Title { get; set; }
82+
public DateTime CreateTime { get; set; }
6783
}
6884
[Fact]
6985
public void ExecuteAffrows()

0 commit comments

Comments
 (0)