@@ -270,6 +270,13 @@ private static List<FieldIdentifier> GetSequenceFields(IStatementBase statement)
270270 return result ;
271271 }
272272
273+ private static bool CanSequence ( IDataMutateOptions options , object value ) => options switch
274+ {
275+ IDataInsertOptions insertion when insertion . SequenceSuppressed => value == null || Convert . IsDBNull ( value ) ,
276+ IDataUpsertOptions upsertion when upsertion . SequenceSuppressed => value == null || Convert . IsDBNull ( value ) ,
277+ _ => value == null || Convert . IsDBNull ( value ) || Zongsoft . Common . Convert . IsZero ( value ) ,
278+ } ;
279+
273280 private static void SetSequenceValue ( IDataMutateContextBase context , IEnumerable < FieldIdentifier > sequenceFileds , object data )
274281 {
275282 if ( data == null || sequenceFileds == null )
@@ -285,7 +292,7 @@ private static void SetSequenceValue(IDataMutateContextBase context, IEnumerable
285292 {
286293 var value = field . Token . GetValue ( data ) ;
287294
288- if ( value == null || Convert . IsDBNull ( value ) || object . Equals ( value , Zongsoft . Common . TypeExtension . GetDefaultValue ( field . Token . MemberType ) ) || ( context . Options is IDataInsertOptions options && ! options . SequenceSuppressed ) )
295+ if ( CanSequence ( context . Options , value ) )
289296 {
290297 var id = ( ( DataAccess ) context . DataAccess ) . Increase ( context , sequence , data ) ;
291298 field . Token . SetValue ( ref data , Convert . ChangeType ( id , field . Token . MemberType ) ) ;
@@ -310,7 +317,7 @@ private static async ValueTask SetSequenceValueAsync(IDataMutateContextBase cont
310317 {
311318 var value = field . Token . GetValue ( data ) ;
312319
313- if ( value == null || Convert . IsDBNull ( value ) || object . Equals ( value , Zongsoft . Common . TypeExtension . GetDefaultValue ( field . Token . MemberType ) ) || ( context . Options is IDataInsertOptions options && ! options . SequenceSuppressed ) )
320+ if ( CanSequence ( context . Options , value ) )
314321 {
315322 var id = await ( ( DataAccess ) context . DataAccess ) . IncreaseAsync ( context , sequence , data , cancellation ) ;
316323 field . Token . SetValue ( ref data , Convert . ChangeType ( id , field . Token . MemberType ) ) ;
0 commit comments