What Is a Unit of Work?
A unit of work is a pattern that records all the objects loaded or modified within a single operation and writes them out together when the operation completes. It coordinates the changes into one transaction, deciding the order of inserts, updates, and deletes. If anything fails, the whole set can be rolled back as a unit.
Why it matters
Batching related changes into one transaction keeps data consistent and reduces round trips. It gives a clear boundary for committing or discarding an entire operation.
Related guides
What Is the Repository Pattern?The repository pattern provides a collection-like interface for accessing domain objects, hiding the details…
What Is a Data Mapper?A data mapper is a layer that moves data between objects and a database while keeping the two independent, so…
What Is Optimistic Locking?Optimistic locking detects conflicting updates at commit time by checking a version field, rather than holdin…