HistoryContext HistoryContext HistoryContext Class

Definition

This class is used by Code First Migrations to read and write migration history from the database. To customize the definition of the migrations history table you can derive from this class and override OnModelCreating. Derived instances can either be registered on a per migrations configuration basis using SetHistoryContextFactory(String, Func<DbConnection,String,HistoryContext>), or globally using SetDefaultHistoryContext(Func<DbConnection,String,HistoryContext>).

public class HistoryContext : System.Data.Entity.DbContext, System.Data.Entity.Infrastructure.IDbModelCacheKeyProvider
type HistoryContext = class
    inherit DbContext
    interface IDbModelCacheKeyProvider
Public Class HistoryContext
Inherits DbContext
Implements IDbModelCacheKeyProvider
Inheritance
HistoryContextHistoryContextHistoryContext
Implements

Constructors

HistoryContext(DbConnection, String) HistoryContext(DbConnection, String) HistoryContext(DbConnection, String)

Initializes a new instance of the HistoryContext class. If you are creating a derived history context you will generally expose a constructor that accepts these same parameters and passes them to this base constructor.

Fields

DefaultTableName DefaultTableName DefaultTableName

The default name used for the migrations history table.

Properties

CacheKey CacheKey CacheKey

Gets the key used to locate a model that was previously built for this context. This is used to avoid processing OnModelCreating and calculating the model every time a new context instance is created. By default this property returns the default schema. In most cases you will not need to override this property. However, if your implementation of OnModelCreating contains conditional logic that results in a different model being built for the same database provider and default schema you should override this property and calculate an appropriate key.

ChangeTracker ChangeTracker ChangeTracker

Provides access to features of the context that deal with change tracking of entities.

(Inherited from DbContext)
Configuration Configuration Configuration

Provides access to configuration options for the context.

(Inherited from DbContext)
Database Database Database

Creates a Database instance for this context that allows for creation/deletion/existence checks for the underlying database.

(Inherited from DbContext)
DefaultSchema DefaultSchema DefaultSchema

Gets the default schema of the model being migrated. This schema will be used for the migrations history table unless a different schema is configured in OnModelCreating.

History History History

Gets or sets a DbSet<TEntity> that can be used to read and write HistoryRow instances.

IObjectContextAdapter.ObjectContext IObjectContextAdapter.ObjectContext IObjectContextAdapter.ObjectContext

Returns the Entity Framework ObjectContext that is underlying this context.

(Inherited from DbContext)

Methods

Dispose() Dispose() Dispose()

Calls the protected Dispose method.

(Inherited from DbContext)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Disposes the context. The underlying ObjectContext is also disposed if it was created is by this context or ownership was passed to this context when this context was created. The connection to the database (DbConnection object) is also disposed if it was created is by this context or ownership was passed to this context when this context was created.

(Inherited from DbContext)
Entry(Object) Entry(Object) Entry(Object)

Gets a DbEntityEntry object for the given entity providing access to information about the entity and the ability to perform actions on the entity.

(Inherited from DbContext)
Entry<TEntity>(TEntity) Entry<TEntity>(TEntity) Entry<TEntity>(TEntity)

Gets a DbEntityEntry<TEntity> object for the given entity providing access to information about the entity and the ability to perform actions on the entity.

(Inherited from DbContext)
Equals(Object) Equals(Object) Equals(Object) Inherited from DbContext
GetHashCode() GetHashCode() GetHashCode() Inherited from DbContext
GetType() GetType() GetType() Inherited from DbContext
GetValidationErrors() GetValidationErrors() GetValidationErrors()

Validates tracked entities and returns a Collection of DbEntityValidationResult containing validation results.

(Inherited from DbContext)
OnModelCreating(DbModelBuilder) OnModelCreating(DbModelBuilder) OnModelCreating(DbModelBuilder)

Applies the default configuration for the migrations history table. If you override this method it is recommended that you call this base implementation before applying your custom configuration.

SaveChanges() SaveChanges() SaveChanges()

Saves all changes made in this context to the underlying database.

(Inherited from DbContext)
SaveChangesAsync() SaveChangesAsync() SaveChangesAsync()

Asynchronously saves all changes made in this context to the underlying database.

(Inherited from DbContext)
SaveChangesAsync(CancellationToken) SaveChangesAsync(CancellationToken) SaveChangesAsync(CancellationToken)

Asynchronously saves all changes made in this context to the underlying database.

(Inherited from DbContext)
Set(Type) Set(Type) Set(Type)

Returns a non-generic DbSet instance for access to entities of the given type in the context and the underlying store.

(Inherited from DbContext)
Set<TEntity>() Set<TEntity>() Set<TEntity>()

Returns a DbSet<TEntity> instance for access to entities of the given type in the context and the underlying store.

(Inherited from DbContext)
ShouldValidateEntity(DbEntityEntry) ShouldValidateEntity(DbEntityEntry) ShouldValidateEntity(DbEntityEntry)

Extension point allowing the user to override the default behavior of validating only added and modified entities.

(Inherited from DbContext)
ToString() ToString() ToString() Inherited from DbContext
ValidateEntity(DbEntityEntry, IDictionary<Object,Object>) ValidateEntity(DbEntityEntry, IDictionary<Object,Object>) ValidateEntity(DbEntityEntry, IDictionary<Object,Object>)

Extension point allowing the user to customize validation of an entity or filter out validation results. Called by GetValidationErrors().

(Inherited from DbContext)

Applies to