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
optionsBuilderDbContextOptionsBuilderThe 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
errorCodesToAddICollection<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
maxRetryCountint
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
maxRetryCountintThe maximum number of retry attempts.
maxRetryDelayTimeSpanThe maximum delay between retries.
errorCodesToAddICollection<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
rangeNamestringThe name of the PostgreSQL range type to be mapped.
subtypeClrTypeTypeThe CLR type of the range's subtype (or element). The actual mapped type will be an NpgsqlRange<T> over this type.
schemaNamestringThe name of the PostgreSQL schema in which the range is defined.
subtypeNamestringOptionally, 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
rangeNamestringThe name of the PostgreSQL range type to be mapped.
schemaNamestringThe name of the PostgreSQL schema in which the range is defined.
subtypeNamestringOptionally, 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
TSubtypeThe 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
callbackProvideClientCertificatesCallbackThe callback to use.
Returns
ProvidePasswordCallback(ProvidePasswordCallback?)
Configures the DbContext to use the specified ProvidePasswordCallback(ProvidePasswordCallback?).
public virtual NpgsqlDbContextOptionsBuilder ProvidePasswordCallback(ProvidePasswordCallback? callback)
Parameters
callbackProvidePasswordCallbackThe callback to use.
Returns
RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?)
Configures the DbContext to use the specified RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?).
public virtual NpgsqlDbContextOptionsBuilder RemoteCertificateValidationCallback(RemoteCertificateValidationCallback? callback)
Parameters
callbackRemoteCertificateValidationCallbackThe 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
postgresVersionVersionThe backend version to target.
Returns
UseAdminDatabase(string?)
Connect to this database for administrative operations (creating/dropping databases).
public virtual NpgsqlDbContextOptionsBuilder UseAdminDatabase(string? dbName)
Parameters
dbNamestringThe 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
useRedshiftboolWhether to target Redshift.