Table of Contents

Class Mutation

Namespace
The.Relationships
Assembly
Instagile.dll

Tracks a call stack that's making changes to entities and their relationships.

public class Mutation : IDisposable
Inheritance
Mutation
Implements
Inherited Members

Remarks

When entity properties or relationships are modified, those changes may trigger cascading modifications (e.g., setting one side of a relationship updates the other side). A Mutation tracks all such changes within a logical operation, deferring change notifications until the outermost mutation completes. This ensures observers see a consistent state rather than intermediate states during a complex operation.

Mutations nest via an AsyncLocal<T> stack: inner mutations share their The.Relationships.Mutation._ModifiedRelationships set with the outer mutation, and only the outermost mutation broadcasts change notifications when disposed. This batching is essential for operations that trigger multiple cascading changes.

Thread safety: Mutations claim their EntityContext to detect concurrent access from different threads. Multiple mutations on the same thread (whether nested or from different async continuations) are allowed because the non-thread-safe ORM operations don't span await points. Concurrent access from different threads throws ConcurrentContextAccessException in DEBUG builds.

Async flow divergence (poisoning): If a mutation is created on one async flow but disposed on another (due to async continuation thread-hopping), the The.Relationships.Mutation._OuterMutation AsyncLocal state becomes inconsistent. The mutation is marked as "poisoned" so that future mutations on the original async flow create fresh mutation stacks rather than attaching to the zombie mutation. This prevents silent loss of change notifications.

Constructors

Mutation(IEntityContext, ILogger)

public Mutation(IEntityContext context, ILogger logger)

Parameters

context IEntityContext
logger ILogger

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

~Mutation()

protected ~Mutation()

RegisterChanged(RelationshipProperty)

public void RegisterChanged(RelationshipProperty notifier)

Parameters

notifier RelationshipProperty