While working with the EF-Core Code-First approach, we first create the classes for our domain entities. Later, we create the database from our code by using migrations. This is the opposite of the Data-First approach, where we design our database first and then create the classes that match our database design.

How Does Entity Framework Core Code-First Approach Work?

Code Example

[Key] attribute will indicate the field with identity key and primary key constraints.

[Required] attribute will make the field required and Not-Null field.

Categories will be your table name in the database

You can get the complete code here from this github: https://github.com/arpitsdotnet/EFCoreExample