8 Configuring advanced features and handling concurrency conflicts

 

This chapter covers

  • Using backing fields with relationships
  • Using an SQL user-defined function in EF Core
  • Configuring SQL column properties
  • Handling concurrency conflicts

This chapter starts with more-advanced approaches to working with a database. These include a method to “hide” a relationship from outside changes, and various ways to move calculations into the database. Then we’ll cover several configuration features that aren’t the normal, run-of-the-mill features, but provide access or control of columns in the database. Although you won’t use these features every day, they can be useful in specific circumstances.

The second half of this chapter is about handling multiple, near-simultaneous updates of the same piece of data in the database; these updates can cause problems known as concurrency conflicts. By default, EF Core uses an Optimistic Concurrency pattern, meaning it’ll take the last value that was written to the database. You’ll learn how to configure just one property/column or a whole entity/table to catch concurrency conflicts, and how to capture and then write code to correct the concurrency conflict.

8.1 Advanced feature—using backing fields with relationships

 
 
 

8.1.1 The problem—the book app performance is too slow

 
 

8.1.2 Our solution—IEnumerable<Review> property and a backing field

 
 
 
 

8.2 DbFunction—using user-defined functions with EF Core

 
 

8.2.1 Configuring a scalar user-defined function

 
 
 

8.2.2 Adding your UDF code to the database

 

8.2.3 Using a registered scalar UDF in your database queries

 
 
 

8.3 Computed column—a dynamically calculated column value

 
 
 
 

8.4 Setting a default value for a database column

 
 
 
 

8.4.1 Adding a constant as a default constraint

 
 

8.4.2 Adding an SQL fragment as a default constraint

 
 

8.4.3 Creating a value generator to generate a default value dynamically

 
 
 

8.5 Sequences—providing numbers in a strict order

 

8.6 Marking database-generated properties

 
 
 

8.6.1 Marking a column that’s generated on an addition or update

 

8.6.2 Marking a column’s value as set on insert of a new row

 
 
 

8.6.3 Marking a column as “normal”

 
 
 
 

8.7 Handling simultaneous updates—concurrency conflicts

 
 
 

8.7.1 Why do concurrency conflicts matter?

 
 

8.7.2 EF Core’s concurrency conflict–handling features

 
 

8.7.3 Handling a DbUpdateConcurrencyException

 
 

8.7.4 The disconnected concurrent update issue

 
 

Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage