To understand transactions, let's create a sample application that we can use to understand the related concepts. Let's create a simple application to simulate bank account scenarios. Just for the sake of simplicity, let's say a hypothetical bank uses separate tables for its various account types. Let's create two tables in the database: one for SalaryAccount
and another for SavingAccount
. The generated Entity Data Model for this sample database will look like the following:
From the application perspective, whenever a user chooses to transfer some money from SalaryAccount
to SavingAccount
, this operation should be treated as a single unit of work. It should never happen that the amount gets debited from SalaryAccount
and never gets credited in the SavingAccount
. Let's use this scenario to see how we can manage transactions using Entity Framework.
The initial amount of 5,000 will be present in SalaryAccount...