@@ -334,26 +334,31 @@ public IUpdate<T1> SetSource(IEnumerable<T1> source)
334334 return this ;
335335 }
336336
337- public IUpdate < T1 > Set < TMember > ( Expression < Func < T1 , TMember > > column , TMember value )
337+ protected void SetPriv ( ColumnInfo col , object value )
338338 {
339- var cols = new List < SelectColumnInfo > ( ) ;
340- _commonExpression . ExpressionSelectColumn_MemberAccess ( null , cols , SelectTableInfoType . From , column ? . Body , true , null ) ;
341- if ( cols . Count != 1 ) return this ;
342- var col = cols . First ( ) ;
343339 object paramVal = null ;
344- if ( col . Column . Attribute . MapType == typeof ( TMember ) ) paramVal = value ;
345- else paramVal = Utils . GetDataReaderValue ( col . Column . Attribute . MapType , value ) ;
346- _set . Append ( ", " ) . Append ( _commonUtils . QuoteSqlName ( col . Column . Attribute . Name ) ) . Append ( " = " ) ;
340+ if ( value != null )
341+ {
342+ if ( col . Attribute . MapType == value . GetType ( ) ) paramVal = value ;
343+ else paramVal = Utils . GetDataReaderValue ( col . Attribute . MapType , value ) ;
344+ }
345+ _set . Append ( ", " ) . Append ( _commonUtils . QuoteSqlName ( col . Attribute . Name ) ) . Append ( " = " ) ;
347346 if ( _noneParameter )
348347 {
349- _set . Append ( _commonUtils . GetNoneParamaterSqlValue ( _params , col . Column . Attribute . MapType , paramVal ) ) ;
348+ _set . Append ( _commonUtils . GetNoneParamaterSqlValue ( _params , col . Attribute . MapType , paramVal ) ) ;
350349 }
351350 else
352351 {
353- _set . Append ( _commonUtils . QuoteWriteParamter ( col . Column . Attribute . MapType , $ "{ _commonUtils . QuoteParamterName ( "p_" ) } { _params . Count } ") ) ;
354- _commonUtils . AppendParamter ( _params , null , col . Column , col . Column . Attribute . MapType , paramVal ) ;
352+ _set . Append ( _commonUtils . QuoteWriteParamter ( col . Attribute . MapType , $ "{ _commonUtils . QuoteParamterName ( "p_" ) } { _params . Count } ") ) ;
353+ _commonUtils . AppendParamter ( _params , null , col , col . Attribute . MapType , paramVal ) ;
355354 }
356- //foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value);
355+ }
356+ public IUpdate < T1 > Set < TMember > ( Expression < Func < T1 , TMember > > column , TMember value )
357+ {
358+ var cols = new List < SelectColumnInfo > ( ) ;
359+ _commonExpression . ExpressionSelectColumn_MemberAccess ( null , cols , SelectTableInfoType . From , column ? . Body , true , null ) ;
360+ if ( cols . Count != 1 ) return this ;
361+ SetPriv ( cols . First ( ) . Column , value ) ;
357362 return this ;
358363 }
359364 public IUpdate < T1 > Set < TMember > ( Expression < Func < T1 , TMember > > exp )
@@ -424,6 +429,27 @@ public IUpdate<T1> SetRaw(string sql, object parms = null)
424429 return this ;
425430 }
426431
432+ public IUpdate < T1 > SetDto ( object dto )
433+ {
434+ if ( dto == null ) return this ;
435+ if ( dto is Dictionary < string , object > )
436+ {
437+ var dic = dto as Dictionary < string , object > ;
438+ foreach ( var kv in dic )
439+ {
440+ if ( _table . ColumnsByCs . TryGetValue ( kv . Key , out var trycol ) == false ) continue ;
441+ SetPriv ( trycol , kv . Value ) ;
442+ }
443+ }
444+ var dtoProps = dto . GetType ( ) . GetProperties ( ) ;
445+ foreach ( var dtoProp in dtoProps )
446+ {
447+ if ( _table . ColumnsByCs . TryGetValue ( dtoProp . Name , out var trycol ) == false ) continue ;
448+ SetPriv ( trycol , dtoProp . GetValue ( dto , null ) ) ;
449+ }
450+ return this ;
451+ }
452+
427453 public IUpdate < T1 > Where ( Expression < Func < T1 , bool > > expression ) => this . Where ( _commonExpression . ExpressionWhereLambdaNoneForeignObject ( null , _table , null , expression ? . Body , null , _params ) ) ;
428454 public IUpdate < T1 > Where ( string sql , object parms = null )
429455 {
0 commit comments