Skip to content

Commit

Permalink
Fix adding value-converted rowversion column (#25998)
Browse files Browse the repository at this point in the history
Fixes #25997
Closes #22980
  • Loading branch information
roji committed Sep 14, 2021
1 parent fc00579 commit 0458d08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,12 @@ protected override void ColumnDefinition(

builder.Append(operation.IsNullable ? " NULL" : " NOT NULL");

DefaultValue(operation.DefaultValue, operation.DefaultValueSql, columnType, builder);
if (!string.Equals(columnType, "rowversion", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(columnType, "timestamp", StringComparison.OrdinalIgnoreCase))
{
// rowversion/timestamp columns cannot have default values, but also don't need them when adding a new column.
DefaultValue(operation.DefaultValue, operation.DefaultValueSql, columnType, builder);
}

var identity = operation[SqlServerAnnotationNames.Identity] as string;
if (identity != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,27 @@ await Test(
@"ALTER TABLE [People] ADD [RowVersion] rowversion NULL;");
}

[ConditionalFact]
public virtual async Task Add_column_with_rowversion_and_value_conversion()
{
await Test(
builder => builder.Entity("People").Property<int>("Id"),
builder => { },
builder => builder.Entity("People").Property<ulong>("RowVersion")
.IsRowVersion()
.HasConversion<byte[]>(),
model =>
{
var table = Assert.Single(model.Tables);
var column = Assert.Single(table.Columns, c => c.Name == "RowVersion");
Assert.Equal("rowversion", column.StoreType);
Assert.True(column.IsRowVersion());
});

AssertSql(
@"ALTER TABLE [People] ADD [RowVersion] rowversion NOT NULL;");
}

public override async Task Add_column_with_defaultValueSql()
{
await base.Add_column_with_defaultValueSql();
Expand Down

0 comments on commit 0458d08

Please sign in to comment.