Skip to content

Commit

Permalink
Fix issue where property with value generated on add is reseeded in e…
Browse files Browse the repository at this point in the history
…very migration

Fixes dotnet#21661
  • Loading branch information
Christopher Haws authored and Christopher Haws committed Jul 18, 2020
1 parent 1aac0ae commit 9e4769f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ protected virtual Dictionary<IEntityType, List<ITable>> DiffData(

foreach (var targetProperty in entry.EntityType.GetProperties())
{
if (targetProperty.ValueGenerated != ValueGenerated.Never)
if (!(targetProperty.ValueGenerated == ValueGenerated.Never || targetProperty.ValueGenerated == ValueGenerated.OnAdd))
{
continue;
}
Expand Down
37 changes: 37 additions & 0 deletions test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,43 @@ public void SeedData_all_operations()
}));
}

[ConditionalFact]
public void Dont_reseed_value_with_value_generated_on_add_property()
{
Execute(
source => source
.Entity(
"EntityWithValueGeneratedOnAddProperty",
x =>
{
x.Property<int>("Id");
x.Property<string>("ValueGeneratedOnAddProperty")
.ValueGeneratedOnAdd();
x.HasData(
new
{
Id = 1,
ValueGeneratedOnAddProperty = "Value"
});
}),
target => target
.Entity(
"EntityWithValueGeneratedOnAddProperty",
x =>
{
x.Property<int>("Id");
x.Property<string>("ValueGeneratedOnAddProperty")
.ValueGeneratedOnAdd();
x.HasData(
new
{
Id = 1,
ValueGeneratedOnAddProperty = "Value"
});
}),
operations => Assert.Equal(0, operations.Count));
}

[ConditionalFact]
public void Dont_rebuild_index_with_equal_include()
{
Expand Down

0 comments on commit 9e4769f

Please sign in to comment.