public async Task <IEnumerable <string> > MigrateAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var pending = await GetPendingMigrationsAsync(cancellationToken);

            if (pending.Any())
            {
                using (var transaction = _context.Database.BeginTransactionIfNotYetRunnig())
                {
                    using (var historyContext = new DataMigrationContext(_context.Database.Connection))
                    {
                        historyContext.Database.UseTransaction(_context.Database.CurrentTransaction.UnderlyingTransaction);
                        foreach (var item in pending)
                        {
                            var migration = Activator.CreateInstance(_localMigrations[item]);
                            _context.ChangeTracker.Entries().ToList().ForEach(p => p.State = EntityState.Detached);

                            await _invoker(_context, migration, cancellationToken);

                            await _context.SaveChangesAsync();

                            historyContext.HistoryRows.Add(new DataMigrationHistoryRow {
                                MigrationId = item
                            });
                            await historyContext.SaveChangesAsync();
                        }

                        transaction.Commit();
                    }
                }
            }

            return(pending);
        }
        public async Task <IEnumerable <string> > GetAppliedMigrationsAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var historyContext = new DataMigrationContext(_context.Database.Connection))
            {
                if (_context.Database.CurrentTransaction != null)
                {
                    historyContext.Database.UseTransaction(_context.Database.CurrentTransaction.UnderlyingTransaction);
                }

                var appliedMigrations = await historyContext.HistoryRows
                                        .OrderBy(p => p.MigrationId)
                                        .Select(p => p.MigrationId)
                                        .ToListAsync(cancellationToken);

                var localMigrationKeys = _localMigrations.Keys.OrderBy(p => p).ToList();

                appliedMigrations = appliedMigrations.Where(p => _localMigrations.ContainsKey(p)).ToList();

                return(appliedMigrations);
            }
        }