ASP.Net Core MVC – Use SQLite With Entity Framework Core



ASP.Net Core MVC – Use SQLite With Entity Framework Core

ASP.Net Core MVC - Use SQLite With Entity Framework Core

Create a .NET Core 3.1 console application in Visual Studio 2019.

As you might know, ASP.NET is able to support many different types of Database providers. Today, I decided to test the use of SQLite in ASP.NET Core 3.1 with Entity Framework Core. For a quick demonstration, I’ll create a simple console application. You can follow along.

Install Entity Framework Core

When working with EF Core, you will want to install the correct package for the Entity Framework Core database provider you want to target in your project. Since this demo project is regarding SQLite, I am going to install the EF Core that supports SQLite.

Add NuGet package reference
Install-Package Microsoft.EntityFrameworkCore.Sqlite

Create DBContext
we need to create the DBContext. Add a new class file and name it SQLiteDBContext.cs .
DbSet which is used to create the Employees table.
OnConfiguring() method is used for configuring the DBContext. Here the option is set to use Sqlite database and also setting a connection string or data source to connect.

we’ll need to run migration using the following commands in Package Manager Console.
Add-Migration InitialCreate
Update-Database

we’ll need to add Microsoft.EntityFrameworkCore.Tools to allow us to create and apply migration.

asp.net core sqlite
asp.net sqlite
sqlite asp.net core

asp.net sqlite tutorial
sqlite asp.net
sqlite asp.net core
asp.net core mvc sqlite
asp.net core sqlite tutorial
asp.net core sqlite entity framework
asp.net core sqlite no such table
asp.net core mvc sqlite
.net sqlite
.net sqlite tutorial
sqlite .net core
sqlite asp.net

#AspDotNetCore #aspDotNet #Sqlite
#EntityFrameworkCore

Comments are closed.