Class UmbracoDbContext
Inheritance
Namespace: Umbraco.Cms.Persistence.EFCore
Assembly: Umbraco.Cms.Persistence.EFCore.dll
Syntax
public class UmbracoDbContext : DbContext
Remarks
To autogenerate migrations use the following commands and insure the 'src/Umbraco.Web.UI/appsettings.json' have a connection string set with the right provider.
Create a migration for each provider.
dotnet ef migrations add %Name% -s src/Umbraco.Web.UI -p src/Umbraco.Cms.Persistence.EFCore.SqlServer -c UmbracoDbContext
dotnet ef migrations add %Name% -s src/Umbraco.Web.UI -p src/Umbraco.Cms.Persistence.EFCore.Sqlite -c UmbracoDbContext
Remove the last migration for each provider.
dotnet ef migrations remove -s src/Umbraco.Web.UI -p src/Umbraco.Cms.Persistence.EFCore.SqlServer
dotnet ef migrations remove -s src/Umbraco.Web.UI -p src/Umbraco.Cms.Persistence.EFCore.Sqlite
To find documentation about this way of working with the context see https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/providers?tabs=dotnet-core-cli#using-one-context-type
Constructors
View SourceUmbracoDbContext(DbContextOptions<UmbracoDbContext>)
Initializes a new instance of the UmbracoDbContext class.
Declaration
public UmbracoDbContext(DbContextOptions<UmbracoDbContext> options)
Parameters
| Type | Name | Description |
|---|---|---|
| DbContextOptions<UmbracoDbContext> | options |
Methods
View SourceOnModelCreating(ModelBuilder)
Override this method to further configure the model that was discovered by convention from the entity types exposed in Microsoft.EntityFrameworkCore.DbSet<TEntity> properties on your derived context. The resulting model may be cached and re-used for subsequent instances of your derived context.
Declaration
protected override void OnModelCreating(ModelBuilder modelBuilder)
Parameters
| Type | Name | Description |
|---|---|---|
| ModelBuilder | modelBuilder | The builder being used to construct the model for this context. Databases (and other extensions) typically define extension methods on this object that allow you to configure aspects of the model that are specific to a given database. |
Remarks
If a model is explicitly set on the options for this context (via Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.UseModel(Microsoft.EntityFrameworkCore.Metadata.IModel)) then this method will not be run. However, it will still run when creating a compiled model.
See Modeling entity types and relationships for more information and examples.