3
votes

Dotnet Core Web API throws when trying to use SQLite for my application

DbContextOptionsBuilder' does not contain a definition for 'UseSqlite' and no accessible extension method 'UseSqlite'

how to fix this?

I have tried using.Microsoft.EntityFrameworkCore;

using Microsoft.EntityFrameworkCore;

2

2 Answers

6
votes

I solved this problem by adding SQLite package.

On your startup file use this

using Microsoft.EntityFrameworkCore;

On your project file use this

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1"/>

then you are ready to use SQLite

services.AddDbContext<DataContext>(x => 
    x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
0
votes

If you get this error you might have forgotten to install the Microsoft.EntityFrameworkCore.Sqlite package

In Visual Studio go to Tools > NuGet Package Manager > Package Manager Console and type:

Install-Package Microsoft.EntityFrameworkCore.Sqlite

Or if you're using .NET CLI type this in your shell:

dotnet add package Microsoft.EntityFrameworkCore.Sqlite

This command will also add the corresponding <PackageReference ..> tag to the project file as mentioned by RedWan.