EF Core – Inheritance mapping

There are two ways to do inheritance mapping in EF Core: Let’s say we have a database with employees. All employees have an id and a name. There are currently two types of employees: programmers and drivers. Programmers have a language (ex: C#), and drivers have a car (ex: Honda). We can model this with … Read more

EF Core – How to add a computed column

To add a computed column in EF Core, override DbContext.OnModelCreating() and specify the computed column using ModelBuilder, like this: In this article, I’ll show a full example of adding a computed column and then show how to specify that the computed column should be persisted. Example of adding a computed column Let’s say we have … Read more

EF Core – How to create a composite primary key

A composite primary key is a primary key that contains more than one column. In EF Core, when you are creating (or modifying) a table, you can, you can use the [Key] attribute to create primary key with one column. To create a composite primary key with multiple columns, you have to override DbContext.OnModelCreating() and … Read more