Table of Contents

Class DbContextExtensions

Namespace
FishMMO.Database.Npgsql
Assembly
FishMMO-DB.dll

Extension methods for NpgsqlDbContext to provide dynamic table name resolution.

public static class DbContextExtensions
Inheritance
DbContextExtensions
Inherited Members

Methods

GetTableName<TEntity>(NpgsqlDbContext)

Gets the fully qualified table name (schema.table_name) for the specified entity type.

public static string GetTableName<TEntity>(this NpgsqlDbContext context) where TEntity : class

Parameters

context NpgsqlDbContext

The database context.

Returns

string

The fully qualified table name in the format "schema.table_name".

Type Parameters

TEntity

The entity type.

Remarks

Identifier Safety: The schema and table name are resolved from EF Core metadata (not user input). However, SQL identifiers cannot be passed as parameters. When using interpolated SQL APIs (e.g., ExecuteSqlInterpolatedAsync or FromSqlInterpolated), EF Core parameterizes the interpolated holes, which would turn the table name into a SQL parameter and break the statement.

Required Usage: Embed the returned identifier into SQL text and use ExecuteSqlRaw/FromSqlRaw with parameter placeholders ({0}, {1}, ...) for values. Never build SQL by concatenating untrusted strings.

Exceptions

ArgumentNullException

Thrown when context is null.

DatabaseException

Thrown when the entity metadata resolves to an unsafe or missing identifier.