Class NpgsqlDbContextOptionsBuilder
- 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
DbContextOptionsBuilderThe 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
intThe maximum number of retry attempts.
maxRetryDelay
TimeSpanThe 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
stringThe name of the PostgreSQL range type to be mapped.
subtypeClrType
TypeThe CLR type of the range's subtype (or element). The actual mapped type will be an NpgsqlRange<T> over this type.
schemaName
stringThe name of the PostgreSQL schema in which the range is defined.
subtypeName
stringOptionally, the name of the range's PostgreSQL subtype (or element). This is usually not needed - the subtype will be inferred based on
subtypeClrType
.
Returns
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
stringThe name of the PostgreSQL range type to be mapped.
schemaName
stringThe name of the PostgreSQL schema in which the range is defined.
subtypeName
stringOptionally, the name of the range's PostgreSQL subtype (or element). This is usually not needed - the subtype will be inferred based on
TSubtype
.
Returns
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?)
Configures the DbContext to use the specified ProvideClientCertificatesCallback(ProvideClientCertificatesCallback?).
public virtual NpgsqlDbContextOptionsBuilder ProvideClientCertificatesCallback(ProvideClientCertificatesCallback? callback)
Parameters
callback
ProvideClientCertificatesCallbackThe callback to use.
Returns
ProvidePasswordCallback(ProvidePasswordCallback?)
Configures the DbContext to use the specified ProvidePasswordCallback(ProvidePasswordCallback?).
public virtual NpgsqlDbContextOptionsBuilder ProvidePasswordCallback(ProvidePasswordCallback? callback)
Parameters
callback
ProvidePasswordCallbackThe callback to use.
Returns
RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?)
Configures the DbContext to use the specified RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?).
public virtual NpgsqlDbContextOptionsBuilder RemoteCertificateValidationCallback(RemoteCertificateValidationCallback? callback)
Parameters
callback
RemoteCertificateValidationCallbackThe callback to use.
Returns
SetPostgresVersion(int, int)
Configures the backend version to target.
public virtual NpgsqlDbContextOptionsBuilder SetPostgresVersion(int major, int minor)
Parameters
Returns
SetPostgresVersion(Version?)
Configures the backend version to target.
public virtual NpgsqlDbContextOptionsBuilder SetPostgresVersion(Version? postgresVersion)
Parameters
postgresVersion
VersionThe backend version to target.
Returns
UseAdminDatabase(string?)
Connect to this database for administrative operations (creating/dropping databases).
public virtual NpgsqlDbContextOptionsBuilder UseAdminDatabase(string? dbName)
Parameters
dbName
stringThe name of the database for administrative operations.
Returns
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
boolWhether to target Redshift.