@@ -336,33 +336,35 @@ private async Task<object> GetNextVersionAsync(FlushEntityEvent @event, Cancella
336
336
/// to synchronize its state to the database. Modifies the event by side-effect!
337
337
/// Note: this method is quite slow, avoid calling if possible!
338
338
/// </summary>
339
- protected Task < bool > IsUpdateNecessaryAsync ( FlushEntityEvent @event , CancellationToken cancellationToken )
339
+ protected async Task < bool > IsUpdateNecessaryAsync ( FlushEntityEvent @event , CancellationToken cancellationToken )
340
340
{
341
- if ( cancellationToken . IsCancellationRequested )
342
- {
343
- return Task . FromCanceled < bool > ( cancellationToken ) ;
344
- }
341
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
345
342
IEntityPersister persister = @event . EntityEntry . Persister ;
346
343
Status status = @event . EntityEntry . Status ;
347
344
348
345
if ( ! @event . DirtyCheckPossible )
349
346
{
350
- return Task . FromResult < bool > ( true ) ;
347
+ return true ;
351
348
}
352
349
else
353
350
{
351
+ // call to HasDirtyCollections must not be optimized away because of its side effect
352
+ bool hasDirtyCollections = await ( HasDirtyCollectionsAsync ( @event , persister , status , cancellationToken ) ) . ConfigureAwait ( false ) ;
353
+
354
354
int [ ] dirtyProperties = @event . DirtyProperties ;
355
- if ( dirtyProperties != null && dirtyProperties . Length != 0 )
356
- {
357
- return Task . FromResult < bool > ( true ) ; //TODO: suck into event class
358
- }
359
- else
360
- {
361
- return HasDirtyCollectionsAsync ( @event , persister , status , cancellationToken ) ;
362
- }
355
+ return dirtyProperties != null && dirtyProperties . Length != 0 || hasDirtyCollections ;
363
356
}
364
357
}
365
358
359
+ /// <summary>
360
+ /// Check if there are any dirty collections.
361
+ /// Has a side effect of setting the HasDirtyCollection property of the event.
362
+ /// </summary>
363
+ /// <param name="event"></param>
364
+ /// <param name="persister"></param>
365
+ /// <param name="status"></param>
366
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
367
+ /// <returns></returns>
366
368
private async Task < bool > HasDirtyCollectionsAsync ( FlushEntityEvent @event , IEntityPersister persister , Status status , CancellationToken cancellationToken )
367
369
{
368
370
cancellationToken . ThrowIfCancellationRequested ( ) ;
0 commit comments