From the course: Using Entity Framework Core with Legacy Databases

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Using shadow properties

Using shadow properties

From the course: Using Entity Framework Core with Legacy Databases

Start my 1-month free trial

Using shadow properties

- [Instructor] Earlier, we added fields to the model that were not on the database. Now we're going to go the other direction, and have database fields not on our model. These fields are called shadow properties. Shadow properties are another way that we can separate our code from the gritty details of the database. A simple model reduces the mental load when developing against it, and can reduce bugs and errors in the resulting code. If a field with a similar name should be used in the application, removing it from the model is an easy way to prevent its use. Shadow properties are created by convention. When in a model, a relationship exists, but the foreign key property doesn't. If we look at our order model, we can see we have a relationship to customer, and to sales person. We also have customer ID, and sales person ID. These are the foreign keys for that relationship. Having these foreign keys in the model can be particularly useful. And when we scaffold the database, they will…

Contents