- 修复 MySql + InsertOrUpdateDict + IfExistsDoNothing 错误;#1601

This commit is contained in:
2881099
2023-08-24 11:20:19 +08:00
parent 3ab8bb5ec6
commit dd1f64a772
6 changed files with 57 additions and 44 deletions

View File

@ -88,12 +88,18 @@ namespace FreeSql.Custom.MySql
{
if (_tempPrimarys.Any() == false) throw new Exception(CoreStrings.Entity_Must_Primary_Key("fsql.InsertOrUpdate + IfExistsDoNothing + MySql ", _table.CsName));
sql = insert.ToSqlValuesOrSelectUnionAllExtension101(false, (rowd, idx, sb) =>
sb.Append(" \r\n FROM dual WHERE NOT EXISTS(").Append(
_orm.Select<T1>()
.AsTable((_, __) => _tableRule?.Invoke(__)).AsType(_table.Type)
.DisableGlobalFilter()
.WhereDynamic(rowd)
.Limit(1).ToSql("1").Replace(" \r\n", " \r\n ")).Append(")"));
{
sb.Append(" \r\n FROM dual WHERE NOT EXISTS(");
if (typeof(T1) == typeof(Dictionary<string, object>) && rowd is T1 dict)
sb.Append($"SELECT 1 FROM {_commonUtils.QuoteSqlName(_tableRule(null))} WHERE {_commonUtils.WhereItems<T1>(_tempPrimarys, "", new T1[] { dict })})");
else
sb.Append(
_orm.Select<T1>()
.AsTable((_, __) => _tableRule?.Invoke(__)).AsType(_table.Type)
.DisableGlobalFilter()
.WhereDynamic(rowd)
.Limit(1).ToSql("1").Replace(" \r\n", " \r\n ")).Append(")");
});
}
}
if (string.IsNullOrEmpty(sql)) return null;