Home > Software engineering >  Scaffolding an existing SQLite database with EF core results in a generic context and no entities fo
Scaffolding an existing SQLite database with EF core results in a generic context and no entities fo

Time:11-08

The command I'm inputting into pmc is Scaffold-DbContext "DataSource=C:\SQLite\Databases\Ticket0.db3" Microsoft.EntityFrameworkCore.Sqlite -OutputDir C:\WPFTutorials\TicketEF\TicketEF\DB -context TicketContext -force I've checked and double checked the data source, but it only generates a generic context and no tables (I can't include images as I don't have high enough reputation).

I also checked on stack overflow but the closest relevant post I could find was this SQLite scaffolding with Entity Framework Core, however the problem there was relative pathing whereas I am using an absolute path. Another I tried was Scaffold (reverse engineering) existing database return empty sets and tried commenting out the <Nullable>enable</Nullable> which solved their issue but that didn't work either.

I have the

Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.Sqlite and Microsoft.EntityFrameworkCore.Tools

NuGet packages installed.

In case it matters the database I am trying to connect can be opened and changed in SQLiteStudio so it should be working fine, and it has 5 tables and 2 views.

CodePudding user response:

I have modified your code to the below and it's working.

Scaffold-DbContext -provider Microsoft.EntityFrameworkCore.Sqlite "DataSource=C:\SQLite\Databases\Ticket0.db3" -OutputDir C:\WPFTutorials\TicketEF\TicketEF\DB -context TicketContext -force

CodePudding user response:

What had happened was that I mistyped the database location as "Ticket0" which is how it appeared in SQLiteStudio and EF Core generated an empty Ticket0.db3 which I'd then mistaken for the original file.

Since it's my own mistake should I delete the question?

  • Related