Skip to content

Commit

Permalink
Make setting CurrentValue to null actually set the property to null
Browse files Browse the repository at this point in the history
Issue #7920

Previously we were not setting the property to null if it was marked as required--we were instead setting conceptual null. But when the CLR type is nullable, we don't need conceptual nulls, so just set the property to null.
  • Loading branch information
ajcvickers committed Jun 26, 2017
1 parent 68ef618 commit e4e47c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public virtual void SetProperty([NotNull] IPropertyBase propertyBase, [CanBeNull
var writeValue = true;

if (asProperty != null
&& (!asProperty.IsNullable
&& (!asProperty.ClrType.IsNullableType()
|| asProperty.GetContainingForeignKeys().Any(
p => p.DeleteBehavior == DeleteBehavior.Cascade
|| p.DeleteBehavior == DeleteBehavior.Restrict)))
Expand Down
10 changes: 4 additions & 6 deletions test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void SetValues_with_IsModified_can_mark_a_set_of_values_as_changed()

entry.CurrentValues.SetValues(disconnectedEntity);

Assert.Equal("A", trackedEntity.Name);
Assert.Null(trackedEntity.Name);
Assert.Equal("NewLongName", trackedEntity.LongName);

Assert.False(entry.Property(e => e.Id).IsModified);
Expand All @@ -81,7 +81,7 @@ public void SetValues_with_IsModified_can_mark_a_set_of_values_as_changed()
var internalEntry = entry.GetInfrastructure();

Assert.False(internalEntry.IsConceptualNull(entry.Property(e => e.Id).Metadata));
Assert.True(internalEntry.IsConceptualNull(entry.Property(e => e.Name).Metadata));
Assert.False(internalEntry.IsConceptualNull(entry.Property(e => e.Name).Metadata));
Assert.False(internalEntry.IsConceptualNull(entry.Property(e => e.LongName).Metadata));

foreach (var property in entry.Properties)
Expand Down Expand Up @@ -223,14 +223,12 @@ public void Can_set_current_value_to_null()
new PropertyEntry(entry, "RequiredPrimate").CurrentValue = null;

Assert.Null(entity.Primate);
Assert.True(entry.IsConceptualNull(new PropertyEntry(entry, "RequiredPrimate").Metadata));
Assert.Equal("Tarsier", entity.RequiredPrimate);
Assert.Null(entity.RequiredPrimate);

context.ChangeTracker.DetectChanges();

Assert.Null(entity.Primate);
Assert.True(entry.IsConceptualNull(new PropertyEntry(entry, "RequiredPrimate").Metadata));
Assert.Equal("Tarsier", entity.RequiredPrimate);
Assert.Null(entity.RequiredPrimate);
}
}

Expand Down

0 comments on commit e4e47c8

Please sign in to comment.