Class NpgsqlServiceCollectionExtensions
Provides extension methods to configure Entity Framework Core for Npgsql.
Inheritance
Namespace: Microsoft.Extensions.DependencyInjection
Assembly: Npgsql.EntityFrameworkCore.PostgreSQL.dll
Syntax
public static class NpgsqlServiceCollectionExtensions
Methods
| Improve this Doc View SourceAddEntityFrameworkNpgsql(IServiceCollection)
Adds the services required by the Npgsql database provider for Entity Framework
to an
Calling this method is no longer necessary when building most applications, including those that
use dependency injection in ASP.NET or elsewhere.
It is only needed when building the internal service provider for use with
the
Declaration
public static IServiceCollection AddEntityFrameworkNpgsql(this IServiceCollection serviceCollection)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | serviceCollection | The |
Returns
Type | Description |
---|---|
IServiceCollection | The same service collection so that multiple calls can be chained. |
AddNpgsql<TContext>(IServiceCollection, string?, Action<NpgsqlDbContextOptionsBuilder>?, Action<DbContextOptionsBuilder>?)
Registers the given Entity Framework context as a service in the
Use this method when using dependency injection in your application, such as with ASP.NET Core.
For applications that don't use dependency injection, consider creating
To configure the
For more information on how to use this method, see the Entity Framework Core documentation at https://aka.ms/efdocs. For more information on using dependency injection, see https://go.microsoft.com/fwlink/?LinkId=526890.
Declaration
public static IServiceCollection AddNpgsql<TContext>(this IServiceCollection serviceCollection, string? connectionString, Action<NpgsqlDbContextOptionsBuilder>? npgsqlOptionsAction = null, Action<DbContextOptionsBuilder>? optionsAction = null) where TContext : DbContext
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | serviceCollection | The |
string? | connectionString | The connection string of the database to connect to. |
Action<><NpgsqlDbContextOptionsBuilder>? | npgsqlOptionsAction | An optional action to allow additional SQL Server specific configuration. |
Action<><DbContextOptionsBuilder>? | optionsAction | An optional action to configure the |
Returns
Type | Description |
---|---|
IServiceCollection | The same service collection so that multiple calls can be chained. |
Type Parameters
Name | Description |
---|---|
TContext | The type of context to be registered. |