Make It Real – Handling Concurrencies

We have explored transactions, without which real-world transactions are not possible. We started with the default behavior and then went on to creating a transaction. Later, we learned about how a transaction could be shared between contexts, and finally we concluded by learning how external transactions were handled.

Let's identify the real-world problems available with respect to concurrencies, and we will see how we could handle them using the EF Core Framework:

  • In a real-world application, the same data store might be accessed by different modules at the same time. How does EF Core handle those persistences?
    • EF Core has a few concurrency techniques that help us in creating a fail-safe mechanism.
  • In which mechanism does EF Core expose concurrency techniques?
    • It exposes them using the usual techniques—data annotation and Fluent API.
  • Do we need to add anything to the design to support concurrency?
    • It's a paradox; yes and no. If we are marking a column for concurrency checks then no schema change is required; otherwise, we need to introduce a timestamp/date row version column.
  • Do we have any provision in not having such a column in a data model but still support concurrency tokens?
    • Yeah, it's quite possible. In the No foreign key property section of Chapter 3Relationships - Terminology and Conventions, we discussed shadow properties. The same concept could be applied here where EF Core does internal concurrency checks without exposing them in the data model in a context.
  • Nothing is fail-safe. Even if we build the mechanism to handle concurrencies, what control do we have if we face this conflict? What would be the action item and how do we ensure that the application is really fail-safe?
    • We could capture concurrency issues, and deal with current, original, and database values to resolve them.

The sections we will be including in this chapter are:

  • Handling concurrency in EF
  • Introducing concurrency tokens
  • Concurrency tokens through shadow properties
  • Concurrency tokens based on timestamp/row version
  • Handling concurrency conflicts
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset