Repository: dotnet/efcore
File: src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs (C#)

Code before:

                    if (temporalInformation.IsTemporalTable)
                    {
                        if (alterColumnOperation.OldColumn.ComputedColumnSql != alterColumnOperation.ComputedColumnSql)
                        {
                            throw new NotSupportedException(
                                SqlServerStrings.TemporalMigrationModifyingComputedColumnNotSupported(
                                    alterColumnOperation.Name,
                                    alterColumnOperation.Table));
                        }

                        // for alter column operation converting column from nullable to non-nullable in the temporal table
                        // we must disable versioning in order to properly handle it
                        // specifically, switching values in history table from null to the default value
                        var changeToNonNullable = alterColumnOperation.OldColumn.IsNullable
                            && !alterColumnOperation.IsNullable;

                        // for alter column converting to sparse we also need to disable versioning
                        // in case HistoryTable is compressed (so that we can de-compress it)
                        var changeToSparse = alterColumnOperation.OldColumn[SqlServerAnnotationNames.Sparse] as bool? != true
                            && alterColumnOperation[SqlServerAnnotationNames.Sparse] as bool? == true;

                        // for alter column removing default value we also need to disable versioning
                        // because the default constraint needs to be removed from both main and history tables
                        var removingDefaultValue = (alterColumnOperation.OldColumn.DefaultValue != null || alterColumnOperation.OldColumn.DefaultValueSql != null)
                            && alterColumnOperation.DefaultValue == null && alterColumnOperation.DefaultValueSql == null;

                        if (changeToNonNullable || changeToSparse || removingDefaultValue)
                        {
                            DisableVersioning(
                                tableName!,
                                schema,
                                temporalInformation,
                                suppressTransaction,
                                shouldEnableVersioning: true);
                        }

                        if (changeToSparse)
                        {
                            DecompressTable(
                                temporalInformation.HistoryTableName!, temporalInformation.HistoryTableSchema, suppressTransaction);
                        }

                        operations.Add(alterColumnOperation);

                        // when modifying a period column, we need to perform the operations as a normal column first, and only later enable period
                        // removing the period information now, so that when we generate SQL that modifies the column we won't be making them auto generated as period
                        // (making column auto generated is not allowed in ALTER COLUMN statement)
                        // in later operation we enable the period and the period columns get set to auto generated automatically
                        //
                        // if the column is not period we just remove temporal information - it's no longer needed and could affect the generated sql

Review comment (suggestion):
Specifically since DefaultValue is object and can be anything (and so may override the equality operator etc).

```suggestion
                        var removingDefaultValue = (alterColumnOperation.OldColumn.DefaultValue is not null || alterColumnOperation.OldColumn.DefaultValueSql is not null)
                            && alterColumnOperation.DefaultValue is null && alterColumnOperation.DefaultValueSql is null;
```

Code after:

                    if (temporalInformation.IsTemporalTable)
                    {
                        if (alterColumnOperation.OldColumn.ComputedColumnSql != alterColumnOperation.ComputedColumnSql)
                        {
                            throw new NotSupportedException(
                                SqlServerStrings.TemporalMigrationModifyingComputedColumnNotSupported(
                                    alterColumnOperation.Name,
                                    alterColumnOperation.Table));
                        }

                        // for alter column operation converting column from nullable to non-nullable in the temporal table
                        // we must disable versioning in order to properly handle it
                        // specifically, switching values in history table from null to the default value
                        var changeToNonNullable = alterColumnOperation.OldColumn.IsNullable
                            && !alterColumnOperation.IsNullable;

                        // for alter column converting to sparse we also need to disable versioning
                        // in case HistoryTable is compressed (so that we can de-compress it)
                        var changeToSparse = alterColumnOperation.OldColumn[SqlServerAnnotationNames.Sparse] as bool? != true
                            && alterColumnOperation[SqlServerAnnotationNames.Sparse] as bool? == true;

                        // for alter column removing default value we also need to disable versioning
                        // because the default constraint needs to be removed from both main and history tables
                        var removingDefaultValue = (alterColumnOperation.OldColumn.DefaultValue is not null || alterColumnOperation.OldColumn.DefaultValueSql is not null)
                            && alterColumnOperation.DefaultValue is null && alterColumnOperation.DefaultValueSql is null;

                        if (changeToNonNullable || changeToSparse || removingDefaultValue)
                        {
                            DisableVersioning(
                                tableName!,
                                schema,
                                temporalInformation,
                                suppressTransaction,
                                shouldEnableVersioning: true);
                        }

                        if (changeToSparse)
                        {
                            DecompressTable(
                                temporalInformation.HistoryTableName!, temporalInformation.HistoryTableSchema, suppressTransaction);
                        }

                        operations.Add(alterColumnOperation);

                        // when modifying a period column, we need to perform the operations as a normal column first, and only later enable period
                        // removing the period information now, so that when we generate SQL that modifies the column we won't be making them auto generated as period
                        // (making column auto generated is not allowed in ALTER COLUMN statement)
                        // in later operation we enable the period and the period columns get set to auto generated automatically
                        //
                        // if the column is not period we just remove temporal information - it's no longer needed and could affect the generated sql