Example #1
0
        public static IEnumerable <string> GetAvailableProviders(this DbMigrationsConfiguration configuration)
        {
            // Marcus Miris @ 19/Out/2016:
            // ... tudo isso apenas para basicamente retornar a string "System.Data.SqlClient" sem hardcode...
            // Explicando: o Entity Framework tem vários Dependencies Resolvers internos para resolver
            // diversas questões. Uma delas são os providers registrados. Os providers podem ser registrados
            // [1] no AppConfig; [2] no DbMigrationConfiguration; [3] No DbConfiguration.
            // O código abaixo varre todos os resolvers do Entity Framework à procura dos providers.
            var defaultProviders = from resolver in configuration.GetDependencyResolver().GetInternalResolvers()
                                   where resolver is SingletonDependencyResolver <Func <MigrationSqlGenerator> >
                                   let keyPredicate = resolver.GetPrivateField <Func <object, bool> >(@"_keyPredicate")
                                                      select keyPredicate.Target.GetPrivateFieldValue("key") as string;

            // retorna também os providers que foram registrados pelo caller.
            var customProviders = from keyValuePair in configuration.GetPrivateField <Dictionary <string, MigrationSqlGenerator> >("_sqlGenerators")
                                  select keyValuePair.Key;

            return(defaultProviders
                   .Union(customProviders)
                   .DefaultIfEmpty("System.Data.SqlClient"));
        }
Example #2
0
 /// <summary>
 ///     Recupera o <see cref="IDbDependencyResolver"/> utilizado
 ///     pelo <see cref="DbMigrationsConfiguration"/> informado.
 /// </summary>
 private static IDbDependencyResolver GetDependencyResolver(this DbMigrationsConfiguration configuration)
 => configuration.GetPrivateField <Lazy <IDbDependencyResolver> >("_resolver")?.Value;