Class UmbracoEFCoreServiceCollectionExtensions
Provides extension methods for registering EF Core services with Umbraco.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Cms.Persistence.EFCore.dll
Syntax
public static class UmbracoEFCoreServiceCollectionExtensions
Methods
View SourceAddUmbracoDbContext<T>(IServiceCollection, Action<DbContextOptionsBuilder, string?, string?, IServiceProvider?>?)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
[Obsolete("Use the overload accepting shareUmbracoConnection. Scheduled for removal in Umbraco 19.")]
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<DbContextOptionsBuilder, string?, string?, IServiceProvider?>? optionsAction = null) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | |
| Action<DbContextOptionsBuilder, string, string, IServiceProvider> | optionsAction |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
AddUmbracoDbContext<T>(IServiceCollection, Action<DbContextOptionsBuilder, string?, string?, IServiceProvider?>?, bool)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<DbContextOptionsBuilder, string?, string?, IServiceProvider?>? optionsAction, bool shareUmbracoConnection) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection. |
| Action<DbContextOptionsBuilder, string, string, IServiceProvider> | optionsAction | An optional action to configure the DbContext options. |
| bool | shareUmbracoConnection | When |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
AddUmbracoDbContext<T>(IServiceCollection, Action<DbContextOptionsBuilder>?)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
[Obsolete("Please use the method overload that takes all parameters for the optionsAction. Scheduled for removal in Umbraco 18.")]
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<DbContextOptionsBuilder>? optionsAction = null) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | |
| Action<DbContextOptionsBuilder> | optionsAction |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
AddUmbracoDbContext<T>(IServiceCollection, Action<IServiceProvider, DbContextOptionsBuilder, string?, string?>?)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
[Obsolete("Use the overload accepting shareUmbracoConnection. Scheduled for removal in Umbraco 19.")]
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<IServiceProvider, DbContextOptionsBuilder, string?, string?>? optionsAction = null) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | |
| Action<IServiceProvider, DbContextOptionsBuilder, string, string> | optionsAction |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
AddUmbracoDbContext<T>(IServiceCollection, Action<IServiceProvider, DbContextOptionsBuilder, string?, string?>?, bool)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<IServiceProvider, DbContextOptionsBuilder, string?, string?>? optionsAction, bool shareUmbracoConnection) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection. |
| Action<IServiceProvider, DbContextOptionsBuilder, string, string> | optionsAction | An optional action to configure the DbContext options. |
| bool | shareUmbracoConnection | When |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
AddUmbracoDbContext<T>(IServiceCollection, Action<IServiceProvider, DbContextOptionsBuilder>?)
Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
Declaration
[Obsolete("Please use the method overload that takes all parameters for the optionsAction. Scheduled for removal in Umbraco 18.")]
public static IServiceCollection AddUmbracoDbContext<T>(this IServiceCollection services, Action<IServiceProvider, DbContextOptionsBuilder>? optionsAction = null) where T : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | |
| Action<IServiceProvider, DbContextOptionsBuilder> | optionsAction |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Type Parameters
| Name | Description |
|---|---|
| T |
UseDatabaseProvider(DbContextOptionsBuilder, string, string)
Sets the database provider. I.E UseSqlite or UseSqlServer based on the provider name.
Declaration
public static void UseDatabaseProvider(this DbContextOptionsBuilder builder, string providerName, string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| DbContextOptionsBuilder | builder | The DbContext options builder. |
| string | providerName | The database provider name. |
| string | connectionString | The connection string. |
Remarks
Only supports the databases normally supported in Umbraco.
Exceptions
| Type | Condition |
|---|---|
| InvalidDataException | Thrown when the provider is not supported. |
UseUmbracoDatabaseProvider(DbContextOptionsBuilder, IServiceProvider)
Sets the database provider to use based on the Umbraco connection string.
Declaration
public static void UseUmbracoDatabaseProvider(this DbContextOptionsBuilder builder, IServiceProvider serviceProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| DbContextOptionsBuilder | builder | The DbContext options builder. |
| IServiceProvider | serviceProvider | The service provider to resolve connection string settings from. |