7 Configuring nonrelational properties

 

This chapter covers

  • Configuring EF Core three ways
  • Focusing on nonrelational properties
  • Defining the database structure
  • Introducing value converters, shadow properties, and backing fields
  • Deciding which type of configuration works best in different situations

This chapter introduces configuring EF Core in general but concentrates on configuring the nonrelational properties in an entity class; these properties are known as scalar properties. Chapter 8 covers configuring relational properties, and chapter 10 covers configuring more-advanced features, such as DbFunctions, computed columns, and so on.

This chapter starts with an overview of the configuration process that EF Core runs when the application’s DbContext is used for the first time. Then you’ll learn how to configure the mapping between the .NET classes and their associated database tables, with features such as setting the name, SQL type, and nullability of the columns in a table.

7.1 Three ways of configuring EF Core

7.2 A worked example of configuring EF Core

7.3 Configuring by convention

7.3.1 Conventions for entity classes

7.3.2 Conventions for parameters in an entity class

7.3.3 Conventions for name, type, and size

7.3.4 By convention, the nullability of a property is based on .NET type

7.3.5 An EF Core naming convention identifies primary keys

7.4 Configuring via Data Annotations

7.4.1 Using annotations from System.ComponentModel.DataAnnotations

7.4.2 Using annotations from System.ComponentModel.DataAnnotations.Schema

7.5 Configuring via the Fluent API

7.6 Excluding properties and classes from the database