You might argue that we do not need unit of work in the previous situation as we are only saving a single entity using one call to ISession.Save
. But remember that saving an employee instance results in multiple database records being inserted, and ideally, the whole operation of inserting these multiple records in database should be an atomic operation. Unit of work guarantees the atomicity we need. Before we bring a notion of unit of work, I would like to spend some time talking about scope of unit of work in this particular situation. A unit of work has to begin somewhere and end somewhere. Determining where unit of work begins and ends is crucial to robustness of data access layer.
Learning NHibernate 4
Learning NHibernate 4
Overview of this book
Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
Introduction to NHibernate
Let's Build a Simple Application
Let's Tell NHibernate About Our Database
NHibernate Warm-up
Let's Store Some Data into the Database
Let's Retrieve Some Data from the Database
Optimizing the Data Access Layer
Using NHibernate in a Real-world Application
Advanced Data Access Patterns
Working with Legacy Database
A Whirlwind Tour of Other NHibernate Features
Index
Customer Reviews