Dev Ethio
Dev Ethio

Reputation: 153

DbContextOptionsBuilder does not contain a definition for 'UseSqlite'

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;

Upvotes: 15

Views: 10209

Answers (3)

Mohsen Zahedi
Mohsen Zahedi

Reputation: 688

I had the same problem in my UnitTest project and it was solved after installing this package:

Microsoft.EntityFrameworkCore.Sqlite.Core

Upvotes: 0

metatron
metatron

Reputation: 999

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.

Upvotes: 12

Redwan
Redwan

Reputation: 426

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")));

Upvotes: 22

Related Questions