Ejemplo n.º 1
0
        private IEnumerable <Func <IReadOnlyList <MigrationCommand> > > GetMigrationCommandLists(
            IReadOnlyList <HistoryRow> appliedMigrationEntries,
            string targetMigration = null)
        {
            IReadOnlyList <Migration> migrationsToApply, migrationsToRevert;

            PopulateMigrations(
                appliedMigrationEntries.Select(t => t.MigrationId),
                targetMigration,
                out migrationsToApply,
                out migrationsToRevert);

            for (var i = 0; i < migrationsToRevert.Count; i++)
            {
                var migration = migrationsToRevert[i];

                var index = i;
                yield return(() =>
                {
                    _logger.LogInformation(
                        RelationalEventId.RevertingMigration,
                        () => RelationalStrings.RevertingMigration(migration.GetId()));

                    return GenerateDownSql(
                        migration,
                        index != migrationsToRevert.Count - 1
                                ? migrationsToRevert[index + 1]
                                : null);
                });
            }

            foreach (var migration in migrationsToApply)
            {
                yield return(() =>
                {
                    _logger.LogInformation(
                        RelationalEventId.ApplyingMigration,
                        () => RelationalStrings.ApplyingMigration(migration.GetId()));

                    return GenerateUpSql(migration);
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual int ExecuteTransaction(
            IEnumerable <IUpdateEntry> entries,
            IInterceptingLogger <LoggerCategory.Update> updateLogger)
        {
            var rowsAffected = 0;

            lock (_lock)
            {
                foreach (var entry in entries)
                {
                    var entityType = entry.EntityType;

                    Debug.Assert(!entityType.IsAbstract());

                    IInMemoryTable table;
                    if (!_tables.Value.TryGetValue(entityType, out table))
                    {
                        _tables.Value.Add(entityType, table = _tableFactory.Create(entityType));
                    }

                    switch (entry.EntityState)
                    {
                    case EntityState.Added:
                        table.Create(entry);
                        break;

                    case EntityState.Deleted:
                        table.Delete(entry);
                        break;

                    case EntityState.Modified:
                        table.Update(entry);
                        break;
                    }

                    rowsAffected++;
                }
            }

            updateLogger.LogInformation <object>(
                InMemoryEventId.SavedChanges,
                rowsAffected,
                InMemoryStrings.LogSavedChanges);

            return(rowsAffected);
        }