- 补充 fsql.InsertOrUpdate UpdateColumns 数据存在时只更新指定的字段;

This commit is contained in:
28810
2020-07-29 15:32:14 +08:00
parent a8d1db8614
commit 06b301395f
19 changed files with 89 additions and 26 deletions

View File

@ -43,7 +43,12 @@ namespace FreeSql.Odbc.MySql
{
insert.InsertIdentity();
if (_doNothing == false)
sql = new OdbcMySqlOnDuplicateKeyUpdate<T1>(insert).ToSql();
{
var cols = _table.Columns.Values.Where(a => a.Attribute.IsPrimary == false && a.Attribute.CanUpdate == true && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
sql = new OdbcMySqlOnDuplicateKeyUpdate<T1>(insert)
.UpdateColumns(cols.Select(a => a.Attribute.Name).ToArray())
.ToSql();
}
else
{
if (_table.Primarys.Any() == false) throw new Exception($"fsql.InsertOrUpdate + IfExistsDoNothing + MySql 要求实体类 {_table.CsName} 必须有主键");