# 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
  object
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>
  NpgsqlDbContextOptionsBuilder

Implements
  IRelationalDbContextOptionsBuilderInfrastructure

Inherited Members
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.MaxBatchSize(int)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.MinBatchSize(int)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.CommandTimeout(int?)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.MigrationsAssembly(string)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.MigrationsAssembly(Assembly)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.MigrationsHistoryTable(string, string)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.UseRelationalNulls(bool)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.UseQuerySplittingBehavior(QuerySplittingBehavior)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.ExecutionStrategy(Func<ExecutionStrategyDependencies, IExecutionStrategy>)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.TranslateParameterizedCollectionsToConstants()
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.TranslateParameterizedCollectionsToParameters()
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.UseParameterizedCollectionMode(ParameterTranslationMode)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.WithOption(Func<NpgsqlOptionsExtension, NpgsqlOptionsExtension>)
  RelationalDbContextOptionsBuilder<NpgsqlDbContextOptionsBuilder, NpgsqlOptionsExtension>.OptionsBuilder
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite(NpgsqlDbContextOptionsBuilder, CoordinateSequenceFactory?, PrecisionModel?, Ordinates, bool)
  NpgsqlNodaTimeDbContextOptionsBuilderExtensions.UseNodaTime(NpgsqlDbContextOptionsBuilder)

## Constructors

### NpgsqlDbContextOptionsBuilder(DbContextOptionsBuilder)

Initializes a new instance of the NpgsqlDbContextOptionsBuilder class.

    public NpgsqlDbContextOptionsBuilder(DbContextOptionsBuilder optionsBuilder)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  The core options builder.

## Methods

### ConfigureDataSource(Action<NpgsqlDataSourceBuilder>)

Configures lower-level Npgsql options at the ADO.NET driver level.

    public virtual NpgsqlDbContextOptionsBuilder ConfigureDataSource(Action<NpgsqlDataSourceBuilder> dataSourceBuilderAction)

#### Parameters

`dataSourceBuilderAction` Action<NpgsqlDataSourceBuilder>

  A lambda to configure Npgsql options on NpgsqlDataSourceBuilder.

#### Returns

NpgsqlDbContextOptionsBuilder

#### Remarks

Changes made by ConfigureDataSource(Action<NpgsqlDataSourceBuilder>) are untracked; When using OnConfiguring(DbContextOptionsBuilder), EF Core will by default resolve the same NpgsqlDataSource internally, disregarding differing configuration across calls to ConfigureDataSource(Action<NpgsqlDataSourceBuilder>). Either make sure that ConfigureDataSource(Action<NpgsqlDataSourceBuilder>) always sets the same configuration, or pass externally-provided, pre-configured data source instances when configuring the provider.

### 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.

### MapEnum(Type, string?, string?, INpgsqlNameTranslator?)

Maps a PostgreSQL enum type for use.

    public virtual NpgsqlDbContextOptionsBuilder MapEnum(Type clrType, string? enumName = null, string? schemaName = null, INpgsqlNameTranslator? nameTranslator = null)

#### Parameters

`clrType` Type

  The CLR type of the enum.

`enumName` string

  The name of the PostgreSQL enum type to be mapped.

`schemaName` string

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

`nameTranslator` INpgsqlNameTranslator

  The name translator used to map enum value names to PostgreSQL enum values.

#### Returns

NpgsqlDbContextOptionsBuilder

### MapEnum<T>(string?, string?, INpgsqlNameTranslator?)

Maps a PostgreSQL enum type for use.

    public virtual NpgsqlDbContextOptionsBuilder MapEnum<T>(string? enumName = null, string? schemaName = null, INpgsqlNameTranslator? nameTranslator = null) where T : struct, Enum

#### Parameters

`enumName` string

  The name of the PostgreSQL enum type to be mapped.

`schemaName` string

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

`nameTranslator` INpgsqlNameTranslator

  The name translator used to map enum value names to PostgreSQL enum values.

#### Returns

NpgsqlDbContextOptionsBuilder

#### Type Parameters

`T`

### 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?)

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

    [Obsolete("Call ConfigureDataSource() and configure the client certificates on the NpgsqlDataSourceBuilder, or pass an externally-built, pre-configured NpgsqlDataSource to UseNpgsql().")]
    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?).

    [Obsolete("Call ConfigureDataSource() and configure the password callback on the NpgsqlDataSourceBuilder, or pass an externally-built, pre-configured NpgsqlDataSource to UseNpgsql().")]
    public virtual NpgsqlDbContextOptionsBuilder ProvidePasswordCallback(ProvidePasswordCallback? callback)

#### Parameters

`callback` ProvidePasswordCallback

  The callback to use.

#### Returns

NpgsqlDbContextOptionsBuilder

### RemoteCertificateValidationCallback(RemoteCertificateValidationCallback?)

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

    [Obsolete("Call ConfigureDataSource() and configure remote certificate validation on the NpgsqlDataSourceBuilder, or pass an externally-built, pre-configured NpgsqlDataSource to UseNpgsql().")]
    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