Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 8 #213

Merged
merged 15 commits into from
Jul 2, 2024
16 changes: 15 additions & 1 deletion LeaderboardBackend/Models/Entities/ApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Data;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Npgsql;
Expand Down Expand Up @@ -31,9 +32,22 @@ public ApplicationContext(DbContextOptions<ApplicationContext> options)
public void MigrateDatabase()
{
Database.Migrate();
bool tempConnection = false;
NpgsqlConnection connection = (NpgsqlConnection)Database.GetDbConnection();
zysim marked this conversation as resolved.
Show resolved Hide resolved

if (connection.State is ConnectionState.Closed)
{
tempConnection = true;
Database.OpenConnection();
}

// when new extensions have been enabled by migrations, Npgsql's type cache must be refreshed
((NpgsqlConnection)Database.GetDbConnection()).ReloadTypes();
connection.ReloadTypes();

if (tempConnection)
{
Database.CloseConnection();
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down