Use DbContext with options.

This commit is contained in:
Kevin Matsubara 2025-04-14 16:54:50 +02:00
parent cbcfb5536d
commit d67d05d6a2

View File

@ -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<DeadBallZoneLeagueDbContext>();
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();