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, to create a primary key with one column, you would use the [Key] attribute. To create a composite primary key with multiple columns, you have to override DbContext.OnModelCreating() and then specify all of the columns included in the … Read more

EF Core – How to add indexes

In this article, I’ll show how to add indexes using EF Core. If you’re not sure about why you would need indexes, take a look at this article explaining how indexes greatly improve query performance. Add an index with a single column The simplest way to add an index is to by adding the [Index] … Read more