mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-07 00:40:55 +08:00
Merge branch 'master' of https://github.com/hnlyf888/FreeSql
This commit is contained in:
@@ -98,11 +98,37 @@ ON CONFLICT(""id"") DO UPDATE SET
|
||||
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
|
||||
class tbiou02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TempPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou_temp>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou_temp>().SetSource(new tbiou_temp { name = "01", description = "testval" }, m => new { m.name });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou_temp""(""name"", ""description"") VALUES('01', 'testval')
|
||||
ON CONFLICT(""name"") DO UPDATE SET
|
||||
""description"" = EXCLUDED.""description""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
var iou2 = fsql.InsertOrUpdate<tbiou_temp>().SetSource(new tbiou_temp { name = "01", description = "testval2" }, m => new { m.name }).ExecuteAffrows();
|
||||
Assert.Equal(1, iou2);
|
||||
|
||||
}
|
||||
[Index("uix_tbiou_temp_name", "name", true)]
|
||||
class tbiou_temp
|
||||
{
|
||||
[Column(IsPrimary = true, IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
public string description { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace FreeSql.Custom.PostgreSQL
|
||||
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
|
||||
else
|
||||
{
|
||||
var ocdu = new CustomPostgreSQLOnConflictDoUpdate<T1>(insert.InsertIdentity());
|
||||
var ocdu = new CustomPostgreSQLOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
|
||||
ocdu._tempPrimarys = _tempPrimarys;
|
||||
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
|
||||
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace FreeSql.KingbaseES
|
||||
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
|
||||
else
|
||||
{
|
||||
var ocdu = new KingbaseESOnConflictDoUpdate<T1>(insert.InsertIdentity());
|
||||
var ocdu = new KingbaseESOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
|
||||
ocdu._tempPrimarys = _tempPrimarys;
|
||||
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
|
||||
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
|
||||
else
|
||||
{
|
||||
var ocdu = new OdbcPostgreSQLOnConflictDoUpdate<T1>(insert.InsertIdentity());
|
||||
var ocdu = new OdbcPostgreSQLOnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
|
||||
ocdu._tempPrimarys = _tempPrimarys;
|
||||
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
|
||||
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace FreeSql.PostgreSQL.Curd
|
||||
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
|
||||
else
|
||||
{
|
||||
var ocdu = new OnConflictDoUpdate<T1>(insert.InsertIdentity());
|
||||
var ocdu = new OnConflictDoUpdate<T1>(_tempPrimarys?.Length > 0 ? insert : insert.InsertIdentity());
|
||||
ocdu._tempPrimarys = _tempPrimarys;
|
||||
var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) ||
|
||||
_tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
|
||||
|
||||
Reference in New Issue
Block a user