Skip to content

Commit 67b9c9c

Browse files
authored
Merge branch 'dotnetcore:master' into master
2 parents a4a6a18 + cf7d8f7 commit 67b9c9c

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

FreeSql.Tests/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLInsertOrUpdateTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,37 @@ ON CONFLICT(""id"") DO UPDATE SET
9898
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
9999
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
100100
}
101+
101102
class tbiou02
102103
{
103104
public int id { get; set; }
104105
public string name { get; set; }
105106
}
107+
108+
[Fact]
109+
public void InsertOrUpdate_TempPrimary()
110+
{
111+
fsql.Delete<tbiou_temp>().Where("1=1").ExecuteAffrows();
112+
var iou = fsql.InsertOrUpdate<tbiou_temp>().SetSource(new tbiou_temp { name = "01", description = "testval" }, m => new { m.name });
113+
var sql = iou.ToSql();
114+
Assert.Equal(@"INSERT INTO ""tbiou_temp""(""name"", ""description"") VALUES('01', 'testval')
115+
ON CONFLICT(""name"") DO UPDATE SET
116+
""description"" = EXCLUDED.""description""", sql);
117+
Assert.Equal(1, iou.ExecuteAffrows());
118+
119+
var iou2 = fsql.InsertOrUpdate<tbiou_temp>().SetSource(new tbiou_temp { name = "01", description = "testval2" }, m => new { m.name }).ExecuteAffrows();
120+
Assert.Equal(1, iou2);
121+
122+
}
123+
[Index("uix_tbiou_temp_name", "name", true)]
124+
class tbiou_temp
125+
{
126+
[Column(IsPrimary = true, IsIdentity = true)]
127+
public int id { get; set; }
128+
129+
public string name { get; set; }
130+
public string description { get; set; }
131+
}
106132
[Fact]
107133
public void InsertOrUpdate_OnePrimaryAndIdentity()
108134
{

Providers/FreeSql.Provider.Custom/PostgreSQL/Curd/CustomPostgreSQLInsertOrUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
5656
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
5757
else
5858
{
59-
var ocdu = new CustomPostgreSQLOnConflictDoUpdate<T1>(insert.InsertIdentity());
59+
var ocdu = new CustomPostgreSQLOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
6060
ocdu._tempPrimarys = _tempPrimarys;
6161
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
6262
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);

Providers/FreeSql.Provider.KingbaseES/Curd/KingbaseESInsertOrUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
5656
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
5757
else
5858
{
59-
var ocdu = new KingbaseESOnConflictDoUpdate<T1>(insert.InsertIdentity());
59+
var ocdu = new KingbaseESOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
6060
ocdu._tempPrimarys = _tempPrimarys;
6161
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
6262
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);

Providers/FreeSql.Provider.Odbc/PostgreSQL/Curd/OdbcPostgreSQLInsertOrUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
5656
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
5757
else
5858
{
59-
var ocdu = new OdbcPostgreSQLOnConflictDoUpdate<T1>(insert.InsertIdentity());
59+
var ocdu = new OdbcPostgreSQLOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
6060
ocdu._tempPrimarys = _tempPrimarys;
6161
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
6262
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);

Providers/FreeSql.Provider.PostgreSQL/Curd/PostgreSQLInsertOrUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
5858
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
5959
else
6060
{
61-
var ocdu = new OnConflictDoUpdate<T1>(insert.InsertIdentity());
61+
var ocdu = new OnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
6262
ocdu._tempPrimarys = _tempPrimarys;
6363
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
6464
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);

0 commit comments

Comments
 (0)