0

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.stack.imgur.com/ZqwSn.png
DronBoard
  • 73
  • 2
  • 11
  • 'No Entity Framework provider found for the ADO.NET provider with invariant name 'FirebirdSql.Data.FirebirdClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.' – DronBoard Aug 17 '20 at 11:16

1 Answers1

1
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());
    ...

}
DronBoard
  • 73
  • 2
  • 11