Skip to content

easyextensionsentityframeworkcoredatabase AuditedDbContext

BigMakCode edited this page Aug 5, 2024 · 1 revision

AuditedDbContext Public class

Description

A DbContext instance represents a session with the database and can be used to query and save instances of your entities. DbContext is a combination of the Unit Of Work and Repository patterns. This version of DbContext is designed for automated auditing of entities.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph EasyExtensions.EntityFrameworkCore.Database
  EasyExtensions.EntityFrameworkCore.Database.AuditedDbContext[[AuditedDbContext]]
  end
  subgraph Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.DbContext[[DbContext]]
  end
Microsoft.EntityFrameworkCore.DbContext --> EasyExtensions.EntityFrameworkCore.Database.AuditedDbContext
Loading

Members

Methods

Public methods

Returns Name
int SaveChanges()
Saves all changes made in this context to the database and update Modified and Created datetime.
Task<int> SaveChangesAsync(...)
Saves all changes made in this context to the database and update Modified and Created datetime.

Details

Summary

A DbContext instance represents a session with the database and can be used to query and save instances of your entities. DbContext is a combination of the Unit Of Work and Repository patterns. This version of DbContext is designed for automated auditing of entities.

Remarks

Inheritance

  • DbContext

Constructors

AuditedDbContext [1/2]

protected AuditedDbContext()
Summary

Initializes a new instance of the DbContext class. The DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) method will be called to configure the database (and other options) to be used for this context.

Remarks

See DbContext lifetime, configuration, and initialization for more information and examples.

AuditedDbContext [2/2]

public AuditedDbContext(DbContextOptions options)
Arguments
Type Name Description
DbContextOptions options The options for this context.
Summary

Initializes a new instance of the DbContext class using the specified options. The DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) method will still be called to allow further configuration of the options.

Remarks

See DbContext lifetime, configuration, and initialization and Using DbContextOptions for more information and examples.

Methods

SaveChanges

public override int SaveChanges()
Summary

Saves all changes made in this context to the database and update Modified and Created datetime.

Remarks
Returns

The number of state entries written to the database.

Exceptions
Name Description
DbUpdateException An error is encountered while saving to the database.
DbUpdateConcurrencyException A concurrency violation is encountered while saving to the database.
A concurrency violation occurs when an unexpected number of rows are affected during save.
This is usually because the data in the database has been modified since it was loaded into memory.

SaveChangesAsync [1/2]

public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken)
Arguments
Type Name Description
bool acceptAllChangesOnSuccess Indicates whether ChangeTracker.AcceptAllChanges is called after
the changes have been sent successfully to the database.
CancellationToken cancellationToken A CancellationToken to observe while waiting for the task to complete.
Summary

Saves all changes made in this context to the database and update Modified and Created datetime.

Remarks
Returns

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

Exceptions
Name Description
DbUpdateException An error is encountered while saving to the database.
DbUpdateConcurrencyException A concurrency violation is encountered while saving to the database.
A concurrency violation occurs when an unexpected number of rows are affected during save.
This is usually because the data in the database has been modified since it was loaded into memory.
OperationCanceledException If the CancellationToken is canceled.

SaveChangesAsync [2/2]

public override Task<int> SaveChangesAsync(CancellationToken cancellationToken)
Arguments
Type Name Description
CancellationToken cancellationToken A CancellationToken to observe while waiting for the task to complete.
Summary

Saves all changes made in this context to the database.

Remarks
Returns

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

Exceptions
Name Description
DbUpdateException An error is encountered while saving to the database.
DbUpdateConcurrencyException A concurrency violation is encountered while saving to the database.
A concurrency violation occurs when an unexpected number of rows are affected during save.
This is usually because the data in the database has been modified since it was loaded into memory.
OperationCanceledException If the CancellationToken is canceled.

Generated with ModularDoc

Clone this wiki locally