DbConfiguration.SetDefaultConnectionFactory(IDbConnectionFactory) Method

Definition

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.

protected internal void SetDefaultConnectionFactory (System.Data.Entity.Infrastructure.IDbConnectionFactory connectionFactory);
member this.SetDefaultConnectionFactory : System.Data.Entity.Infrastructure.IDbConnectionFactory -> unit
Protected Friend Sub SetDefaultConnectionFactory (connectionFactory As IDbConnectionFactory)

Parameters

connectionFactory
IDbConnectionFactory

The connection factory.

Remarks

This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for IDbConnectionFactory. This means that, if desired, the same functionality can be achieved using a custom resolver or a resolver backed by an Inversion-of-Control container.

Applies to