Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3004,6 +3004,21 @@ alterTableOperation.OldTable[SqlServerAnnotationNames.TemporalHistoryTableSchema
// as long as their names and types (including nullability) match
// so we remove ComputedColumnSql info, so that the column in history table "appears normal"
addHistoryTableColumnOperation.ComputedColumnSql = null;

// For computed columns, ensure the history table column has the same nullability
// as the computed column in the main table. For persisted computed columns,
// SQL Server typically treats them as non-nullable if the computation is non-nullable.
// We ensure consistency by making the history table column non-nullable and providing a default value.
addHistoryTableColumnOperation.IsNullable = false;
if (addHistoryTableColumnOperation.DefaultValue == null && addHistoryTableColumnOperation.DefaultValueSql == null)
{
// Provide a default value that matches the computed column type
addHistoryTableColumnOperation.DefaultValue = addColumnOperation.ClrType == typeof(int) || addColumnOperation.ClrType == typeof(int?)
? 0
: addColumnOperation.ClrType.IsValueType
? Activator.CreateInstance(addColumnOperation.ClrType)
: null;
}
}

operations.Add(addHistoryTableColumnOperation);
Expand Down Expand Up @@ -3226,6 +3241,8 @@ static TemporalOperationInformation BuildTemporalInformationFromMigrationOperati
};
}



void DisableVersioning(
string tableName,
string? schema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.RegularExpressions;
using Microsoft.EntityFrameworkCore.SqlServer.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.RegularExpressions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;
Expand Down
Loading