Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
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);
Expand Down