I have created an ASP.NET Core 6 MVC web app in Visual Studio Code, but I am having trouble connecting it with an already existing SQLite database file.
I tried adding the database file by moving it into the mvc files but it didn’t work
I have created an ASP.NET Core 6 MVC web app in Visual Studio Code, but I am having trouble connecting it with an already existing SQLite database file.
I tried adding the database file by moving it into the mvc files but it didn’t work
2
Answers
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
appsettings.json
*Note: Connectionstring can vary
DatabaseContext
addpublic DbSet<MyTable> MyTables { get; set; }
*MyTable should be the name of your table*Change query to your needs
I hope this helps. If not, please do not hesitate to respond to me
My working sample:
DBfile
program.cs
Context
Data Model
A simple controller with get method
test output