AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Error: 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlite'

Open dasoussan opened this issue 8 years ago • 25 comments

After registering the database context when attempting to build, this error appears:

error CS1061: 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlite' and no extension method 'UseSqlite' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)

Searched a lot, installed SQLite from https://www.nuget.org/packages/System.Data.SQLite/ , tried searching, all without success. What am I missing? (or what is missing from the step-by-step instructions)?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

dasoussan avatar Jul 06 '18 15:07 dasoussan

@dasoussan You're missing the following code at the top of your Startup.cs file:

using Microsoft.EntityFrameworkCore;

I'll update this section of the tutorial to make the 2 required using statements more obvious.

scottaddie avatar Jul 06 '18 18:07 scottaddie

I'm running into the same issue, but I have the above using statement. Closing and re-opening VS Code removes the error but the build still fails with the same error CS1061 Something pretty funky is going on here.

Smilebags avatar Jul 11 '18 06:07 Smilebags

Adding <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1"/> to a new ItemGroup in the csproj and then restoring seemed to resolve the issue.

Smilebags avatar Jul 11 '18 06:07 Smilebags

I ran into the same issue today, while trying to follow the tutorial, but the comment from Smilebags seems to work for me too.. The tutorial should probably be updated.

Edit: I started from the cross platform tutorial using VS Code.

Ekmansoft avatar Aug 11 '18 14:08 Ekmansoft

This is still a problem BTW. I'm not sure what the reason is either. I've tried the suggestions by @Smilebags but to no avail. I keep getting this error.

image

It doesn't really make sense - the classes are in the right place and the import is correct so what's wrong?

armydee avatar Oct 12 '18 10:10 armydee

That's a really great error message. Add the right using

Rick-Anderson avatar Oct 13 '18 22:10 Rick-Anderson

@Rick-Anderson Love the sarcasm..... image

I restarted VS Code and the error was gone. Appreciate the help..... seriously. Thanks.

armydee avatar Oct 14 '18 21:10 armydee

Adding <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1"/> to a new ItemGroup in the csproj and then restoring seemed to resolve the issue.

Thank you, this solution works for me in creating the MVCmovie VS CODE tutorial

tombradev avatar Nov 28 '18 09:11 tombradev

@Smilebags Kudos, That solved it

courageDeveloper avatar May 14 '19 17:05 courageDeveloper

please check out my answer this is happening due to version https://stackoverflow.com/questions/43098065/entity-framework-core-dbcontextoptionsbuilder-does-not-contain-a-definition-f/56443050#56443050

malwareoverflow avatar Jun 04 '19 11:06 malwareoverflow

FYI, 2019, @Smilebags comment is still the solution. Thanks dude.

LynneKirsch avatar Oct 28 '19 14:10 LynneKirsch

I just changed the Microsoft.EntityFrameworkCore.Sqlite version with NuGet package manager.

mohammad-khoddami avatar Mar 03 '20 08:03 mohammad-khoddami

On the terminal I ran 'dotnet add package Microsoft.EntityFrameworkCore.Sqlite' and it worked for me.

ohms064 avatar Mar 23 '20 17:03 ohms064

Just install Microsoft.EntityFrameworkCore.InMemory package and it will fix the issue

pinpoint-forest avatar Apr 06 '20 10:04 pinpoint-forest

add package Microsoft.EntityFrameworkCore.Sqlite

dianejason avatar May 25 '20 02:05 dianejason

@dasoussan Thank you! I have been trying for 3 days before I found your solution!

Braath1 avatar Jun 08 '20 10:06 Braath1

That's in the tutorial image

Rick-Anderson avatar Jun 08 '20 20:06 Rick-Anderson

Adding the Microsoft.EntityFrameworkCore.InMemory package helped me with the issue.

https://stackoverflow.com/a/56684097/5834961.

ayaanqui avatar Nov 27 '20 05:11 ayaanqui

That's in the tutorial image

Rick-Anderson avatar Nov 27 '20 17:11 Rick-Anderson

@scottaddie

using Microsoft.EntityFrameworkCore;

Indeed this line is missing from Startup.cs when one follows the Razor Pages tutorial

mskiptr avatar Mar 17 '22 11:03 mskiptr