EF supports transactions out of the box, all we need to do is perform SaveChanges() only once;Â it saves changes only if the transaction has been executed successfully, otherwise, the transactions will be rolled back automatically.
Let's investigate how we could practically leverage the default transactional behavior in our blogging system:
- We need two entities that need to be updated in a single web request
- Both the entities should be added/updated in the data context
- With a single SaveChanges(), both entities will be updated in the data store
In the blogging system, let's include support to add one or more tags in posts and learn about default transaction support in parallel with the Tags integration in posts.