Skip to content

Commit 354043a

Browse files
committed
Update summary
1 parent 63e3b52 commit 354043a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Orm/Xtensive.Orm/Orm/Session.Persist.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private async ValueTask Persist(PersistReason reason, bool isAsync, Cancellation
224224
}
225225

226226
/// <summary>
227-
/// Temporarily disables all save changes operations (both explicit ant automatic)
227+
/// Temporarily disables all save changes operations (both explicit ant automatic)
228228
/// for specified <paramref name="target"/>.
229229
/// Such entity is prevented from being persisted to the database,
230230
/// when <see cref="SaveChanges"/> is called or query is executed.
@@ -234,34 +234,37 @@ private async ValueTask Persist(PersistReason reason, bool isAsync, Cancellation
234234
/// all entities that reference <paramref name="target"/> are also pinned automatically.
235235
/// </summary>
236236
/// <param name="target">The entity to disable persisting.</param>
237-
/// <returns>A special object that controls lifetime of such behavior if <paramref name="target"/> was not previously processed by the method,
238-
/// otherwise <see langword="null"/>.</returns>
237+
/// <returns>
238+
/// A special object that controls lifetime of such behavior if <paramref name="target"/> was not previously processed by the method
239+
/// and automatic saving of changes is enabled (<see cref="SessionOptions.AutoSaveChanges"/>),
240+
/// otherwise <see langword="null"/>.
241+
/// </returns>
239242
public IDisposable DisableSaveChanges(IEntity target)
240243
{
241244
EnsureNotDisposed();
242245
ArgumentValidator.EnsureArgumentNotNull(target, "target");
246+
if (!Configuration.Supports(SessionOptions.AutoSaveChanges))
247+
return null; // No need to pin in this case
248+
243249
var targetEntity = (Entity) target;
244250
targetEntity.EnsureNotRemoved();
245-
return Configuration.Supports(SessionOptions.AutoSaveChanges)
246-
? pinner.RegisterRoot(targetEntity.State)
247-
: null; // No need to pin in this case
251+
return pinner.RegisterRoot(targetEntity.State);
248252
}
249253

250254
/// <summary>
251255
/// Temporarily disables only automatic save changes operations before queries, etc.
252256
/// Explicit call of <see cref="SaveChanges"/> will lead to flush changes anyway.
253257
/// If save changes is to be performed due to starting a nested transaction or committing a transaction,
254258
/// active disabling save changes scope will lead to failure.
255-
/// <returns>A special object that controls lifetime of such behavior if there is no active scope,
259+
/// <returns>A special object that controls lifetime of such behavior if there is no active scope
260+
/// and automatic saving of changes is enabled (<see cref="SessionOptions.AutoSaveChanges"/>),
256261
/// otherwise <see langword="null"/>.</returns>
257262
/// </summary>
258263
public IDisposable DisableSaveChanges()
259264
{
260-
if (!Configuration.Supports(SessionOptions.AutoSaveChanges)) {
261-
return null; // No need to pin in this case
265+
if (!Configuration.Supports(SessionOptions.AutoSaveChanges) || disableAutoSaveChanges) {
266+
return null; // No need to pin in these cases
262267
}
263-
if (disableAutoSaveChanges)
264-
return null;
265268

266269
disableAutoSaveChanges = true;
267270
return new Disposable(_ => {
@@ -318,7 +321,7 @@ private void CancelEntitiesChanges()
318321
newEntity.Update(null);
319322
newEntity.PersistenceState = PersistenceState.Removed;
320323
}
321-
324+
322325
foreach (var modifiedEntity in EntityChangeRegistry.GetItems(PersistenceState.Modified)) {
323326
modifiedEntity.RollbackDifference();
324327
modifiedEntity.PersistenceState = PersistenceState.Synchronized;

0 commit comments

Comments
 (0)