6 Configuring nonrelational properties

 

This chapter covers

  • Configuring EF Core
  • Focusing on nonrelational properties
  • Defining the database structure
  • Using shadow properties and backing fields

This chapter is the first of three that look at configuring EF Core, and it concentrates on configuring the nonrelational properties in an entity class, known as scalar properties. Chapter 7 covers configuring relational properties, and chapter 8 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. You’ll then 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.

This chapter also introduces two EF Core features—shadow properties and backing fields —that enable you to control how the data is exposed to the rest of your non-EF Core code. For instance, these features allow you to “hide,” or control access to, data linked to your database. These two features can help you write better, less fragile applications through better control of the developer’s access to the data held in the entity class.

6.1 Three ways of configuring EF Core

 
 
 

6.2 A worked example of configuring EF Core

 
 

6.3 Configuring By Convention

 

6.3.1 Conventions for entity classes

 
 
 

6.3.2 Conventions for parameters in an entity class

 
 
 

6.3.3 Conventions for name, type, and size

 
 

6.3.4 By Convention, the nullability of a property is based on .NET type

 
 
 

6.3.5 An EF Core naming convention identifies primary keys

 
 
 

6.4 Configuring via Data Annotations

 
 
 
 

6.4.1 System.ComponentModel.DataAnnotations

 
 

6.4.2 System.ComponentModel.DataAnnotations.Schema

 
 
 
 

6.5 Configuring via the Fluent API

 
 
 

6.5.1 A better way to structure your Fluent API commands

 
 
 

6.6 Excluding properties and classes from the database

 

6.6.1 Excluding a class or property via Data Annotations

 
 
 

6.6.2 Excluding a class or property via the Fluent API

 
 
 

6.7 Configuring model-level query filters

 
 
 
 

6.8 Setting database column type, size, and nullability

 
 

6.9 The different ways of configuring the primary key

 
 
 

6.9.1 Configuring a primary key via Data Annotations

 
 

6.9.2 Configuring a primary key via the Fluent API

 
 
 

6.10 Adding indexes to database columns

 
 
 

6.11 Configuring the naming on the database side

 
 
 
 

6.11.1 Configuring table names

 

6.11.2 Configuring the schema name, and schema groupings

 
 

6.11.3 Configuring the database column names in a table

 
 
 

6.12 Using specific database-provider Fluent API commands

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage