Table of Contents

Class NpgsqlDbContextOptionsBuilder

Namespace
Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure
Assembly
Npgsql.EntityFrameworkCore.PostgreSQL.dll

Allows for options specific to PostgreSQL to be configured for a DbContext.

public class NpgsqlDbContextOptionsBuilder : RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>, IRelationalDbContextOptionsBuilderInfrastructure
Inheritance
NpgsqlDbContextOptionsBuilder
Implements
Inherited Members
Extension Methods

Constructors

NpgsqlDbContextOptionsBuilder(DbContextOptionsBuilder)

Initializes a new instance of the NpgsqlDbContextOptionsBuilder class.

public NpgsqlDbContextOptionsBuilder(DbContextOptionsBuilder optionsBuilder)

Parameters

optionsBuilder DbContextOptionsBuilder

The core options builder.

Methods

EnableRetryOnFailure()

Configures the context to use the default retrying IExecutionStrategy.

public virtual NpgsqlDbContextOptionsBuilder EnableRetryOnFailure()

Returns

NpgsqlDbContextOptionsBuilder

An instance of NpgsqlDbContextOptionsBuilder configured to use the default retrying IExecutionStrategy.

EnableRetryOnFailure(ICollection<string>?)

Configures the context to use the default retrying IExecutionStrategy.

public virtual NpgsqlDbContextOptionsBuilder EnableRetryOnFailure(ICollection<string>? errorCodesToAdd)

Parameters

errorCodesToAdd ICollection<string>

Additional error codes that should be considered transient.

Returns

NpgsqlDbContextOptionsBuilder

An instance of NpgsqlDbContextOptionsBuilder with the specified parameters.

EnableRetryOnFailure(int)

Configures the context to use the default retrying IExecutionStrategy.

public virtual NpgsqlDbContextOptionsBuilder EnableRetryOnFailure(int maxRetryCount)

Parameters

maxRetryCount int

Returns

NpgsqlDbContextOptionsBuilder

An instance of NpgsqlDbContextOptionsBuilder with the specified parameters.

EnableRetryOnFailure(int, TimeSpan, ICollection<string>?)

Configures the context to use the default retrying IExecutionStrategy.

public virtual NpgsqlDbContextOptionsBuilder EnableRetryOnFailure(int maxRetryCount, TimeSpan maxRetryDelay, ICollection<string>? errorCodesToAdd)

Parameters

maxRetryCount int

The maximum number of retry attempts.

maxRetryDelay TimeSpan

The maximum delay between retries.

errorCodesToAdd ICollection<string>

Additional error codes that should be considered transient.

Returns

NpgsqlDbContextOptionsBuilder

An instance of NpgsqlDbContextOptionsBuilder with the specified parameters.

MapRange(string, Type, string?, string?)

Maps a user-defined PostgreSQL range type for use.

public virtual NpgsqlDbContextOptionsBuilder MapRange(string rangeName, Type subtypeClrType, string? schemaName = null, string? subtypeName = null)

Parameters

rangeName string

The name of the PostgreSQL range type to be mapped.

subtypeClrType Type

The CLR type of the range's subtype (or element). The actual mapped type will be an NpgsqlRange<T> over this type.

schemaName string

The name of the PostgreSQL schema in which the range is defined.

subtypeName string

Optionally, the name of the range's PostgreSQL subtype (or element). This is usually not needed - the subtype will be inferred based on subtypeClrType.

Returns

NpgsqlDbContextOptionsBuilder

Examples

To map a range of PostgreSQL real, use the following:

NpgsqlTypeMappingSource.MapRange("floatrange", typeof(float));

MapRange<TSubtype>(string, string?, string?)

Maps a user-defined PostgreSQL range type for use.

public virtual NpgsqlDbContextOptionsBuilder MapRange<TSubtype>(string rangeName, string? schemaName = null, string? subtypeName = null)

Parameters

rangeName string

The name of the PostgreSQL range type to be mapped.

schemaName string

The name of the PostgreSQL schema in which the range is defined.

subtypeName string

Optionally, the name of the range's PostgreSQL subtype (or element). This is usually not needed - the subtype will be inferred based on TSubtype.

Returns

NpgsqlDbContextOptionsBuilder

Type Parameters

TSubtype

The CLR type of the range's subtype (or element). The actual mapped type will be an NpgsqlRange<T> over this type.

Examples

To map a range of PostgreSQL real, use the following:

NpgsqlTypeMappingSource.MapRange{float}("floatrange");

ProvideClientCertificatesCallback(ProvideClientCertificatesCallback?)

public virtual NpgsqlDbContextOptionsBuilder ProvideClientCertificatesCallback(ProvideClientCertificatesCallback? callback)

Parameters

callback ProvideClientCertificatesCallback

The callback to use.

Returns

NpgsqlDbContextOptionsBuilder

ProvidePasswordCallback(ProvidePasswordCallback?)

Configures the DbContext to use the specified ProvidePasswordCallback(ProvidePasswordCallback?).

public virtual NpgsqlDbContextOptionsBuilder ProvidePasswordCallback(ProvidePasswordCallback? callback)

Parameters

callback ProvidePasswordCallback

The callback to use.

Returns

NpgsqlDbContextOptionsBuilder

RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?)

public virtual NpgsqlDbContextOptionsBuilder RemoteCertificateValidationCallback(RemoteCertificateValidationCallback? callback)

Parameters

callback RemoteCertificateValidationCallback

The callback to use.

Returns

NpgsqlDbContextOptionsBuilder

SetPostgresVersion(int, int)

Configures the backend version to target.

public virtual NpgsqlDbContextOptionsBuilder SetPostgresVersion(int major, int minor)

Parameters

major int

The PostgreSQL major version to target.

minor int

The PostgreSQL minor version to target.

Returns

NpgsqlDbContextOptionsBuilder

SetPostgresVersion(Version?)

Configures the backend version to target.

public virtual NpgsqlDbContextOptionsBuilder SetPostgresVersion(Version? postgresVersion)

Parameters

postgresVersion Version

The backend version to target.

Returns

NpgsqlDbContextOptionsBuilder

UseAdminDatabase(string?)

Connect to this database for administrative operations (creating/dropping databases).

public virtual NpgsqlDbContextOptionsBuilder UseAdminDatabase(string? dbName)

Parameters

dbName string

The name of the database for administrative operations.

Returns

NpgsqlDbContextOptionsBuilder

UseRedshift(bool)

Configures the provider to work in Redshift compatibility mode, which avoids certain unsupported features from modern PostgreSQL versions.

public virtual NpgsqlDbContextOptionsBuilder UseRedshift(bool useRedshift = true)

Parameters

useRedshift bool

Whether to target Redshift.

Returns

NpgsqlDbContextOptionsBuilder