help
Root Question Message
services.AddSingleton<DbConnection>(_ =>
{
SqliteConnectionStringBuilder stringBuilder = new()
{
DataSource = "MemoryDb",
Mode = SqliteOpenMode.Memory
};
SqliteConnection connection = new(stringBuilder.ToString());
connection.Open();
return connection;
});
services.AddDbContext<MerpieContext>((serviceProvider, options) =>
{
var connection = serviceProvider.GetRequiredService<DbConnection>();
options.UseSqlite(connection, sqliteOptions =>
{
sqliteOptions.UseNodaTime();
});
});
DbConnection
and MerpieContext
are being added to the services, but they're not being configured. services.AddSingleton<DbConnection>(_ =>
hit?MerpieContext
?MerpieContext
private void RunMigrations()
{
using var scope = Services.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<MerpieContext>();
context.Database.Migrate();
}
context.Database.Migrate();
that EF can't find the DB file, which I assume is because the connection string is never set.MerpieContext
to the services somewhere elseMerpieContext
because this is supposed to replace any previous configuration.services.AddDbContext<MerpieContext>((serviceProvider, options)
commented out?Migrate()
call works.WebApplicationFactory
.