Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Created November 3, 2024 13:46
Show Gist options
  • Save karenpayneoregon/fcc1b1fbe688b40539562730f2d2f389 to your computer and use it in GitHub Desktop.
Save karenpayneoregon/fcc1b1fbe688b40539562730f2d2f389 to your computer and use it in GitHub Desktop.
EF Core does database exists method
using yournamespace.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
namespace yournamespace.Classes;
internal class EntityHelpers
{
public static bool DatabaseExists()
{
using var context = new Context();
return ((RelationalDatabaseCreator)context.Database.GetService<IDatabaseCreator>()).Exists();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment