From d67d05d6a23330bbbcbbfe50807f214cbe1d9d3d Mon Sep 17 00:00:00 2001 From: Kevin Matsubara Date: Mon, 14 Apr 2025 16:54:50 +0200 Subject: [PATCH] Use DbContext with options. --- EntityFrameworkCore.Console/Program.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index 7524365..bb07364 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -3,7 +3,13 @@ using EntityFrameworkCore.Domain; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -using var context = new DeadBallZoneLeagueDbContext(); + +var folder = Environment.SpecialFolder.LocalApplicationData; +var path = Environment.GetFolderPath(folder); +var dbPath = Path.Combine(path, "DeadBallZoneLeague_EFCore.db"); +var optionsBuilder = new DbContextOptionsBuilder(); +optionsBuilder.UseSqlite($"Data Source={dbPath}"); +using var context = new DeadBallZoneLeagueDbContext(optionsBuilder.Options); // context.Database.Migrate(); // Can be used to automatically migrate on run. context.Database.EnsureCreated();