protected internal void AddDbProviderServices(DbProviderServices provider) { Check.NotNull(provider, "provider"); foreach (var providerInvariantNameAttribute in DbProviderNameAttribute.GetFromType(provider.GetType())) { AddDbProviderServices(providerInvariantNameAttribute.Name, provider); } }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add /// an implementation of <see cref="DbSpatialServices" /> to use for a specific provider. /// </summary> /// <remarks> /// The given spatial provider type should have a <see cref="DbProviderNameAttribute" /> applied to it. /// 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 /// <see cref="DbSpatialServices" />. 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. /// </remarks> /// <param name="spatialProvider"> The spatial provider. </param> protected internal void AddDbSpatialServices(DbSpatialServices spatialProvider) { Check.NotNull(spatialProvider, "spatialProvider"); _internalConfiguration.CheckNotLocked("AddDbSpatialServices"); foreach (var providerInvariantNameAttribute in DbProviderNameAttribute.GetFromType(spatialProvider.GetType())) { RegisterDbSpatialServices(providerInvariantNameAttribute.Name, spatialProvider); } }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add a /// <see cref="MigrationSqlGenerator" /> for use with the associated provider. /// </summary> /// <remarks> /// The <typeparamref name="T" /> type should have a <see cref="DbProviderNameAttribute" /> applied to it. /// This method is typically used by providers to register an associated SQL generator for Code First Migrations. /// It is different from setting the generator in the <see cref="DbMigrationsConfiguration" /> because it allows /// EF to use the Migrations pipeline to create a database even when there is no Migrations configuration in the project /// and/or Migrations are not being explicitly used. /// 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 /// <see cref="MigrationSqlGenerator" />. 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. /// </remarks> /// <typeparam name="T"> /// The type that implements <see cref="MigrationSqlGenerator" />. /// </typeparam> /// <param name="sqlGenerator"> A delegate that returns a new instance of the SQL generator each time it is called. </param> protected internal void AddMigrationSqlGenerator <T>(Func <T> sqlGenerator) where T : MigrationSqlGenerator { Check.NotNull(sqlGenerator, "sqlGenerator"); foreach (var providerInvariantNameAttribute in DbProviderNameAttribute.GetFromType(typeof(T))) { AddMigrationSqlGenerator(providerInvariantNameAttribute.Name, sqlGenerator); } }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add an /// <see cref="IExecutionStrategy" /> for use with the associated provider for the specified server name. /// </summary> /// <remarks> /// The <typeparamref name="T" /> type should have a <see cref="DbProviderNameAttribute" /> applied to it. /// 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 /// <see cref="IExecutionStrategy" />. 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. /// </remarks> /// <typeparam name="T"> /// The type that implements <see cref="IExecutionStrategy" />. /// </typeparam> /// <param name="getExecutionStrategy"> A function that returns a new instance of an execution strategy. </param> /// <param name="serverName"> A string that will be matched against the server name in the connection string. </param> protected internal void AddExecutionStrategy <T>(Func <T> getExecutionStrategy, string serverName) where T : IExecutionStrategy { Check.NotEmpty(serverName, "serverName"); Check.NotNull(getExecutionStrategy, "getExecutionStrategy"); _internalConfiguration.CheckNotLocked("AddExecutionStrategy"); foreach (var providerInvariantNameAttribute in DbProviderNameAttribute.GetFromType(typeof(T))) { _internalConfiguration.AddDependencyResolver( new ExecutionStrategyResolver <T>(providerInvariantNameAttribute.Name, serverName, getExecutionStrategy)); } }
public void Has_ProviderInvariantNameAttribute() { Assert.Equal( "System.Data.SqlClient", DbProviderNameAttribute.GetFromType(typeof(SqlServerMigrationSqlGenerator)).Single().Name); }
public void Has_ProviderInvariantNameAttribute() { Assert.Equal( "System.Data.SqlServerCe.4.0", DbProviderNameAttribute.GetFromType(typeof(SqlCeProviderServices)).Single().Name); }
public void Has_ProviderInvariantNameAttribute() { Assert.Equal( "System.Data.SqlClient", DbProviderNameAttribute.GetFromType(typeof(SqlAzureExecutionStrategy)).Single().Name); }