Pasimme
Pasimme

Reputation: 11

Entity Framework Core with SQLite: ASP.NET application holding onto database in memory

Thanks in advance for your help.

I'm using my Mac to develop and ASP.NET Core application with SQLite as the database (when learning about SQLite and EF Core, I read through this tutorial: https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite). Migrations and updating the database schema are working, but it seems as though the ASP.NET application is holding onto the database in memory.

Two reasons I'm assuming this:

  1. When I use "DB Browser For SQLite" to browse the SQLite the database schema and data, it shows that there is no data in any of the table (schema is present, so migrations are writing to disk)
  2. When I deleted the SQLite database file itself, the ASP.NET site still had the old data from the deleted file! Really weird.

Does anyone know how I can have my application actually write out the data to the SQLite file, and prevent it from storing it in memory?

Thanks again!

DbContext file:

public class EssBomContext : DbContext
{
   public DbSet<Part> Parts { get; set; }
    // Other DbSets removed for brevety

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite("Data Source=sqlite.db");
    }
}

Upvotes: 0

Views: 1606

Answers (1)

Tubs
Tubs

Reputation: 737

"How can I have the Web project use the db in the Data.EF project?"

Possibly optionsBuilder.UseSqlite("Data Source=\Data.EF\sqlite.db");

Upvotes: 0

Related Questions