Reputation: 83
By initializing the MYDbMigrator get the exception about provider not found. Is migration supported by firebird any other way to register the provider. Also tried to configure with appconfig but configuration section system.data cannot be recognized.
The big picture is i am trying to load the migrations from different assemblies and execute them in an order, but i am stuck in to register the provider. It cannot pass the DbConnection to TMigrationsConfiguration.TargetDatabase as it requires the DbConnectionInfo. How to register the FirebiredSql.Data.FirebirdClinent so it could be found during application lifetime.
public abstract class MYBaseEntityContext : DbContext
{
protected MYBaseEntityContext() : base(connection, true)
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
Configuration.AutoDetectChangesEnabled = true;
Configuration.ValidateOnSaveEnabled = true;
}
}
public class MYDbMigrator<TContext, TMigrationsConfiguration> : DbMigrator
where TContext : MYBaseEntityContext
where TMigrationsConfiguration : MYDataMigrationConfiguration<TContext>, new()
{
public MYDbMigrator(DbConnection connection)
: base(new TMigrationsConfiguration()
{
TargetDatabase = new DbConnectionInfo(connection.ConnectionString, "FirebirdSql.Data.FirebirdClient")
})
{ }
}
public class MYDataMigrationConfiguration<TDataContext> :
DbMigrationsConfiguration<TDataContext>
where TDataContext : MYBaseEntityContext
{
public MYDataMigrationConfiguration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
SetHistoryContextFactory("FirebirdSql.Data.FirebirdClient", (connection, defaultSchema) => new BaseHistoryDataContext(connection, defaultSchema));
SetSqlGenerator("FirebirdSql.Data.FirebirdClient", new FbMigrationSqlGenerator());
}
}
private static FbConnection connection
{
get
{
FbConnectionStringBuilder b = new FbConnectionStringBuilder
{
ServerType = FbServerType.Embedded,
UserID = "sysdba",
Password = "masterkey",
DataSource = "localhost",
Database = "MYMigrations.fdb",
ClientLibrary = "fbclient.dll",
Dialect = 3
};
return new FbConnection(b.ToString());
}
}
[![enter image description here][1]][1]
[1]: https://i.sstatic.net/ZqwSn.png
Upvotes: 0
Views: 145
Reputation: 83
public abstract class MYBaseEntityContext : DbContext
{
public class FirebirdConfiguration : DbConfiguration
{
public FirebirdConfiguration()
{
SetDefaultConnectionFactory(new FbConnectionFactory());
SetProviderFactory(FbProviderServices.ProviderInvariantName, FirebirdClientFactory.Instance);
SetProviderServices(FbProviderServices.ProviderInvariantName, FbProviderServices.Instance);
DbProviderFactories.RegisterFactory(FbProviderServices.ProviderInvariantName, FirebirdClientFactory.Instance);
}
}
}
MyApp.OnStartup(StartupEventArgs e)
{
...
DbConfiguration.SetConfiguration(new MYBaseEntityContext.FirebirdConfiguration());
...
}
Upvotes: 1