DbConfiguration Class

Definition

A class derived from this class can be placed in the same assembly as a class derived from DbContext to define Entity Framework configuration for an application. Configuration is set by calling protected methods and setting protected properties of this class in the constructor of your derived type. The type to use can also be registered in the config file of the application. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information about Entity Framework configuration.

public class DbConfiguration
type DbConfiguration = class
Public Class DbConfiguration
Inheritance
DbConfiguration

Constructors

DbConfiguration()

Any class derived from DbConfiguration must have a public parameterless constructor and that constructor should call this constructor.

Properties

DependencyResolver

Gets the IDbDependencyResolver that is being used to resolve service dependencies in the Entity Framework.

Methods

AddDefaultResolver(IDbDependencyResolver)

Call this method from the constructor of a class derived from DbConfiguration to add a IDbDependencyResolver instance to the Chain of Responsibility of resolvers that are used to resolve dependencies needed by the Entity Framework. Unlike the AddDependencyResolver method, this method puts the resolver at the bottom of the Chain of Responsibility such that it will only be used to resolve a dependency that could not be resolved by any of the other resolvers.

AddDependencyResolver(IDbDependencyResolver)

Call this method from the constructor of a class derived from DbConfiguration to add a IDbDependencyResolver instance to the Chain of Responsibility of resolvers that are used to resolve dependencies needed by the Entity Framework.

AddInterceptor(IDbInterceptor)

Call this method from the constructor of a class derived from DbConfiguration to register an IDbInterceptor at application startup. Note that interceptors can also be added and removed at any time using DbInterception.

Equals(Object)

Determines whether the specified object is equal to the current object.

GetHashCode()

Serves as the default hash function.

GetType()

Gets the Type of the current instance.

LoadConfiguration(Assembly)

Attempts to discover and load the DbConfiguration from the given assembly. This method is intended to be used by tooling to ensure that the correct configuration is loaded into the app domain. Tooling should use this method before accessing the DependencyResolver property. If the tooling knows the DbContext type being used, then the LoadConfiguration(Type) method should be used since it gives a greater chance that the correct configuration will be found.

LoadConfiguration(Type)

Attempts to discover and load the DbConfiguration associated with the given DbContext type. This method is intended to be used by tooling to ensure that the correct configuration is loaded into the app domain. Tooling should use this method before accessing the DependencyResolver property.

MemberwiseClone()

Creates a shallow copy of the current Object.

SetConfiguration(DbConfiguration)

The Singleton instance of DbConfiguration for this app domain. This can be set at application start before any Entity Framework features have been used and afterwards should be treated as read-only.

SetContextFactory(Type, Func<DbContext>)

Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor.

SetContextFactory<TContext>(Func<TContext>)

Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor.

SetDatabaseInitializer<TContext>(IDatabaseInitializer<TContext>)

Call this method from the constructor of a class derived from DbConfiguration to set the database initializer to use for the given context type. The database initializer is called when a the given DbContext type is used to access a database for the first time. The default strategy for Code First contexts is an instance of CreateDatabaseIfNotExists<TContext>.

SetDatabaseLogFormatter(Func<DbContext,Action<String>,DatabaseLogFormatter>)

Call this method from the constructor of a class derived from DbConfiguration to set a factory for the type of DatabaseLogFormatter to use with Log.

SetDefaultConnectionFactory(IDbConnectionFactory)

Sets the IDbConnectionFactory that is used to create connections by convention if no other connection string or connection is given to or can be discovered by DbContext. Note that a default connection factory is set in the app.config or web.config file whenever the EntityFramework NuGet package is installed. As for all config file settings, the default connection factory set in the config file will take precedence over any setting made with this method. Therefore the setting must be removed from the config file before calling this method will have any effect. Call this method from the constructor of a class derived from DbConfiguration to change the default connection factory being used.

SetDefaultHistoryContext(Func<DbConnection,String,HistoryContext>)

Call this method from the constructor of a class derived from DbConfiguration to set a Func<T1,T2,TResult> delegate which which be used for creation of the default HistoryContext for a any DbMigrationsConfiguration. This default factory will only be used if no factory is set explicitly in the DbMigrationsConfiguration and if no factory has been registered for the provider in use using the SetHistoryContext(String, Func<DbConnection,String,HistoryContext>) method.

SetDefaultSpatialServices(DbSpatialServices)

Call this method from the constructor of a class derived from DbConfiguration to set the global instance of DbSpatialServices which will be used whenever a spatial provider is required and a provider-specific spatial provider cannot be found. Normally, a provider-specific spatial provider is obtained from the a DbProviderServices implementation which is in turn returned by resolving a service for DbSpatialServices passing the provider invariant name as a key. However, this cannot work for stand-alone instances of DbGeometry and DbGeography since it is impossible to know the spatial provider to use. Therefore, when creating stand-alone instances of DbGeometry and DbGeography the global spatial provider is always used.

SetDefaultTransactionHandler(Func<TransactionHandler>)

Call this method from the constructor of a class derived from DbConfiguration to register a TransactionHandler.

SetExecutionStrategy(String, Func<IDbExecutionStrategy>)

Call this method from the constructor of a class derived from DbConfiguration to register an IDbExecutionStrategy for use with the provider represented by the given invariant name.

SetExecutionStrategy(String, Func<IDbExecutionStrategy>, String)

Call this method from the constructor of a class derived from DbConfiguration to register an IDbExecutionStrategy for use with the provider represented by the given invariant name and for a given server name.

SetHistoryContext(String, Func<DbConnection,String,HistoryContext>)

Call this method from the constructor of a class derived from DbConfiguration to set a Func<T1,T2,TResult> delegate which allows for creation of a customized HistoryContext for the given provider for any DbMigrationsConfiguration that does not have an explicit factory set.

SetManifestTokenResolver(IManifestTokenResolver)

Call this method from the constructor of a class derived from DbConfiguration to set an implementation of IManifestTokenResolver which allows provider manifest tokens to be obtained from connections without necessarily opening the connection.

SetMetadataAnnotationSerializer(String, Func<IMetadataAnnotationSerializer>)

Call this method from the constructor of a class derived from DbConfiguration to set a factory for implementations of IMetadataAnnotationSerializer which allows custom annotations represented by MetadataProperty instances to be serialized to and from the EDMX XML.

SetMigrationSqlGenerator(String, Func<MigrationSqlGenerator>)

Call this method from the constructor of a class derived from DbConfiguration to register a MigrationSqlGenerator for use with the provider represented by the given invariant name.

SetModelCacheKey(Func<DbContext,IDbModelCacheKey>)

Call this method from the constructor of a class derived from DbConfiguration to set a Func<T,TResult> as the model cache key factory which allows the key used to cache the model behind a DbContext to be changed.

SetModelStore(DbModelStore)

Sets a singleton model store implementation (persisted model cache).

SetPluralizationService(IPluralizationService)

Call this method from the constructor of a class derived from DbConfiguration to set the pluralization service.

SetProviderFactory(String, DbProviderFactory)

Call this method from the constructor of a class derived from DbConfiguration to register an ADO.NET provider.

SetProviderFactoryResolver(IDbProviderFactoryResolver)

Call this method from the constructor of a class derived from DbConfiguration to set an implementation of IDbProviderFactoryResolver which allows a DbProviderFactory to be obtained from a DbConnection in cases where the default implementation is not sufficient.

SetProviderServices(String, DbProviderServices)

Call this method from the constructor of a class derived from DbConfiguration to register an Entity Framework provider.

SetSpatialServices(DbProviderInfo, DbSpatialServices)

Call this method from the constructor of a class derived from DbConfiguration to set an implementation of DbSpatialServices to use for a specific provider and provider manifest token.

SetSpatialServices(String, DbSpatialServices)

Call this method from the constructor of a class derived from DbConfiguration to set an implementation of DbSpatialServices to use for a specific provider with any manifest token.

SetTableExistenceChecker(String, TableExistenceChecker)

Call this method from the constructor of a class derived from DbConfiguration to register a database table existence checker for a given provider.

SetTransactionHandler(String, Func<TransactionHandler>)

Call this method from the constructor of a class derived from DbConfiguration to register a TransactionHandler for use with the provider represented by the given invariant name.

SetTransactionHandler(String, Func<TransactionHandler>, String)

Call this method from the constructor of a class derived from DbConfiguration to register a TransactionHandler for use with the provider represented by the given invariant name and for a given server name.

ToString()

Returns a string that represents the current object.

Events

Loaded

Occurs during EF initialization after the DbConfiguration has been constructed but just before it is locked ready for use. Use this event to inspect and/or override services that have been registered before the configuration is locked. Note that this event should be used carefully since it may prevent tooling from discovering the same configuration that is used at runtime.

Applies to