10 Configuring advanced features and handling concurrency conflicts

 

This chapter covers

  • Using an SQL user-defined function in EF Core queries
  • Configuring columns to have default values or computed values
  • Configuring SQL column properties on databases not created by EF Core
  • Handling concurrency conflicts

This chapter discusses several advanced configuration features that interact directly with your SQL database, such as using SQL user-defined functions (UDFs) and computed columns. These features allow you to move some of your calculations or settings into the SQL 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. You’ll learn how to configure one property/ column or a whole entity/table to catch concurrency conflicts, as well as how to capture and then write code to correct the concurrency conflict.

10.1 DbFunction: Using user-defined functions (UDFs) with EF Core

10.1.1 Configuring a scalar-valued UDF

10.1.2 Configuring a table-valued UDF

10.1.3 Adding your UDF code to the database

10.1.4 Using a registered UDF in your database queries

10.2 Computed column: A dynamically calculated column value

10.3 Setting a default value for a database column

10.3.1 Using the HasDefaultValue method to add a constant value for a column

10.3.2 Using the HasDefaultValueSql method to add an SQL command for a column

10.3.3 Using the HasValueGenerator method to assign a value generator to a property

10.4 Sequences: Providing numbers in a strict order

10.5 Marking database-generated properties

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