Entity Framework

Entity Framework is an object-relational mapping (ORM) framework developed by Microsoft. It is a component of the .NET framework that enables developers to work with relational databases using .NET objects.

It supports a wide range of database providers, including SQL Server, Oracle, MySQL and PostgreSQL. It also includes support for advanced features such as transactions, caching, and concurrency control.

To use Entity Framework Core, 4 NuGet packages are needed:

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.<SQLtool>
  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.EntityFrameworkCore.Design

The CLI tool

This component was made by Stratis Dermanoutsos. The code can be found here.

To update it

This component was made by Stratis Dermanoutsos. The code can be found here.

To use it on a project

This component was made by Stratis Dermanoutsos. The code can be found here.

Verify installation

This component was made by Stratis Dermanoutsos. The code can be found here.

Setup

We’ll setup an SQLite database for the sake of an example.

  • Install the necessary tools

    This component was made by Stratis Dermanoutsos. The code can be found here.
  • Create a <file>.db database using SQLite

  • Go to the project’s appsettings.json file and add

    This component was made by Stratis Dermanoutsos. The code can be found here.
  • Create a class inside the Models folder We’ll name it Car for this example

    This component was made by Stratis Dermanoutsos. The code can be found here.
  • Create the ApplicationDbContext class inside the Models folder The file should look like this

    This component was made by Stratis Dermanoutsos. The code can be found here.
  • Go to Startup.cs inside the ConfigureServices method and add

    This component was made by Stratis Dermanoutsos. The code can be found here.

    or, if top level statements,

    This component was made by Stratis Dermanoutsos. The code can be found here.
  • Run

    This component was made by Stratis Dermanoutsos. The code can be found here.

    Notice that, now, there is a <numbers>_AddCarToDb.cs file in the Migrations folder.

  • Update the database and schema by running

    This component was made by Stratis Dermanoutsos. The code can be found here.

Compiled queries

Resources