mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 补充 fsql.InsertOrUpdate UpdateColumns 数据存在时只更新指定的字段;
This commit is contained in:
		@@ -44,7 +44,12 @@ namespace FreeSql.MySql.Curd
 | 
			
		||||
                {
 | 
			
		||||
                    insert.InsertIdentity();
 | 
			
		||||
                    if (_doNothing == false)
 | 
			
		||||
                        sql = new OnDuplicateKeyUpdate<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 OnDuplicateKeyUpdate<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} 必须有主键");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user