Nucleus .Net Core CMS

DbContext Class

Namespace: Nucleus.Data.EntityFramework
Assembly: Nucleus.Data.EntityFramework.dll
Entity-framework dbcontext implementation.
This class includes automatic configuration of the data provider, automatic handling of Models.ModelBase audit properties, and a special SaveChanges overload which allows the caller to limit the scope of saved changes. Modules should inherit this class instead of inheriting Microsoft.EntityFrameworkCore.DbContext.
DbContext (DbContextConfigurator dbContextConfigurator, IHttpContextAccessor httpContextAccessor, ILoggerFactory loggerFactory)
Constructor.
Get or set whether Nucleus entities should be configured in OnModelCreating.
Remarks
The default value is true. Data providers for business applications which reside in a different database to the Nucleus data objects can set this value to false in their constructor in order to prevent Nucleus entities from being added to the entity framework model for this context.
Http context accessor.
Remarks
This is used to determine the current user Id for populating audit columns.
Logger factory used to provide logger instance for entity-framework logs.
AttachClone<T> (<T> original)
Create a shallow copy of the original object and add it to the DbContext change tracker.
Type Parameters
T
Parameters
Name Type
original <T>
ConfigureConventions (ModelConfigurationBuilder configurationBuilder)
Apply model conventions which apply to all entities.
Parameters
Name Type
configurationBuilder Microsoft.EntityFrameworkCore.ModelConfigurationBuilder
CurrentUserId ()
Retrieve the currently logged-on user's Id
ManageSpecialColumns ()
Automatically set properties of entity framework entries before adding or updating the database.
Remarks
Extensions can override this class to perform their own automatic actions.
OnConfiguring (DbContextOptionsBuilder options)
Call the dbContextConfigurator to configure this DbContext.
OnModelCreating (ModelBuilder builder)
Configure the Microsoft.EntityFrameworkCore.ModelBuilder with settings for the Core Nucleus entities.
Parameters
Name Type
builder Microsoft.EntityFrameworkCore.ModelBuilder
SaveChanges ()
Save changes made in this context, after updating audit properties.
SaveChanges (Boolean acceptAllChangesOnSuccess)
Save changes made in this context, after updating audit properties.
Parameters
Name Type
acceptAllChangesOnSuccess Boolean
SaveChanges<TEntity> ()
Save changes made in this context for the type specified by TEntity ONLY, after updating audit properties.
Type Parameters
TEntity
SaveChangesAsync (Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
Save changes made in this context, after updating audit properties.
Parameters
Name Type
acceptAllChangesOnSuccess Boolean
cancellationToken System.Threading.CancellationToken
SaveChangesAsync<TEntity> ()
Save changes made in this context for the type specified by TEntity ONLY, after updating audit properties.
Type Parameters
TEntity