Part of DKNet.EfCore.Relational.Helpers. Read the physical table name and schema from EF Core model metadata without opening a connection.
Use a .NET 10 console project, install this package and Npgsql.EntityFrameworkCore.PostgreSQL 10.x as in the Quick Start. No running database is needed for this metadata example.
using DKNet.EfCore.Relational.Helpers;
using Microsoft.EntityFrameworkCore;
var options = new DbContextOptionsBuilder<DemoDb>()
.UseNpgsql("Host=localhost;Database=unused;Username=unused;Password=unused").Options;
using var db = new DemoDb(options);
Console.WriteLine(db.GetTableName<Item>()); // (, Items)
public sealed class DemoDb(DbContextOptions<DemoDb> options) : DbContext(options)
{
public DbSet<Item> Items => Set<Item>();
}
public sealed class Item { public int Id { get; set; } }
Schema resolution uses GetSchema(), then GetDefaultSchema(), then dbo for SQL Server only. Table resolution uses GetTableName() then GetDefaultTableName().
(null, null); the existence checker instead throws for that case.