# Class NpgsqlDbContextOptionsBuilderExtensions

Namespace
  Microsoft.EntityFrameworkCore

Assembly
  Npgsql.EntityFrameworkCore.PostgreSQL.dll

Provides extension methods on DbContextOptionsBuilder and DbContextOptionsBuilder<TContext> used to configure a DbContext to context to a PostgreSQL database with Npgsql.

    public static class NpgsqlDbContextOptionsBuilderExtensions

Inheritance
  object
  NpgsqlDbContextOptionsBuilderExtensions

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## Methods

### UseNpgsql(DbContextOptionsBuilder, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL server with Npgsql, but without initially setting any DbConnection or connection string.

The connection or connection string must be set before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection, bool). Set a connection string using SetConnectionString(DatabaseFacade, string).

    public static DbContextOptionsBuilder UseNpgsql(this DbContextOptionsBuilder optionsBuilder, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  The builder being used to configure the context.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder

  The options builder so that further configuration can be chained.

### UseNpgsql(DbContextOptionsBuilder, DbConnection, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder UseNpgsql(this DbContextOptionsBuilder optionsBuilder, DbConnection connection, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  The builder being used to configure the context.

`connection` DbConnection

  An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed. The caller owns the connection and is responsible for its disposal.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder

  The options builder so that further configuration can be chained.

### UseNpgsql(DbContextOptionsBuilder, DbConnection, bool, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder UseNpgsql(this DbContextOptionsBuilder optionsBuilder, DbConnection connection, bool contextOwnsConnection, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  A builder for setting options on the context.

`connection` DbConnection

  An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed.

`contextOwnsConnection` bool

  If true, then EF will take ownership of the connection and will dispose it in the same way it would dispose a connection created by EF. If false, then the caller still owns the connection and is responsible for its disposal.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder

  The options builder so that further configuration can be chained.

### UseNpgsql(DbContextOptionsBuilder, DbDataSource, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder UseNpgsql(this DbContextOptionsBuilder optionsBuilder, DbDataSource dataSource, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  A builder for setting options on the context.

`dataSource` DbDataSource

  A DbDataSource which will be used to get database connections.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder

  The options builder so that further configuration can be chained.

### UseNpgsql(DbContextOptionsBuilder, string?, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder UseNpgsql(this DbContextOptionsBuilder optionsBuilder, string? connectionString, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null)

#### Parameters

`optionsBuilder` DbContextOptionsBuilder

  A builder for setting options on the context.

`connectionString` string

  The connection string of the database to connect to.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder

  The options builder so that further configuration can be chained.

### UseNpgsql<TContext>(DbContextOptionsBuilder<TContext>, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL server with Npgsql, but without initially setting any DbConnection, DbDataSource or connection string.

The connection, data source or connection string must be set explicitly or registered in the DI before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection, bool), a data source using SetDbDataSource(DatabaseFacade, DbDataSource), or a connection string using SetConnectionString(DatabaseFacade, string).

    public static DbContextOptionsBuilder<TContext> UseNpgsql<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null) where TContext : DbContext

#### Parameters

`optionsBuilder` DbContextOptionsBuilder<TContext>

  The builder being used to configure the context.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder<TContext>

  The options builder so that further configuration can be chained.

#### Type Parameters

`TContext`

### UseNpgsql<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder<TContext> UseNpgsql<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, DbConnection connection, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null) where TContext : DbContext

#### Parameters

`optionsBuilder` DbContextOptionsBuilder<TContext>

  A builder for setting options on the context.

`connection` DbConnection

  An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed. The caller owns the connection and is responsible for its disposal.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder<TContext>

  The options builder so that further configuration can be chained.

#### Type Parameters

`TContext`

### UseNpgsql<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, bool, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder<TContext> UseNpgsql<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, DbConnection connection, bool contextOwnsConnection, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null) where TContext : DbContext

#### Parameters

`optionsBuilder` DbContextOptionsBuilder<TContext>

  The builder being used to configure the context.

`connection` DbConnection

  An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed.

`contextOwnsConnection` bool

  If true, then EF will take ownership of the connection and will dispose it in the same way it would dispose a connection created by EF. If false, then the caller still owns the connection and is responsible for its disposal.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder<TContext>

  The options builder so that further configuration can be chained.

#### Type Parameters

`TContext`

  The type of context to be configured.

### UseNpgsql<TContext>(DbContextOptionsBuilder<TContext>, DbDataSource, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder<TContext> UseNpgsql<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, DbDataSource dataSource, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null) where TContext : DbContext

#### Parameters

`optionsBuilder` DbContextOptionsBuilder<TContext>

  A builder for setting options on the context.

`dataSource` DbDataSource

  A DbDataSource which will be used to get database connections.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-specific configuration.

#### Returns

DbContextOptionsBuilder<TContext>

  The options builder so that further configuration can be chained.

#### Type Parameters

`TContext`

### UseNpgsql<TContext>(DbContextOptionsBuilder<TContext>, string?, Action<NpgsqlDbContextOptionsBuilder>?)

Configures the context to connect to a PostgreSQL database with Npgsql.

    public static DbContextOptionsBuilder<TContext> UseNpgsql<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, string? connectionString, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null) where TContext : DbContext

#### Parameters

`optionsBuilder` DbContextOptionsBuilder<TContext>

  A builder for setting options on the context.

`connectionString` string

  The connection string of the database to connect to.

`npgsqlOptionsAction` Action<NpgsqlDbContextOptionsBuilder>

  An optional action to allow additional Npgsql-configuration.

#### Returns

DbContextOptionsBuilder<TContext>

  The options builder so that further configuration can be chained.

#### Type Parameters

`TContext`