Skip to content

Commit

Permalink
Fix for 21041. All concurrency properties can store store-generated v…
Browse files Browse the repository at this point in the history
…alues. (#21128)

Make all concurrency properties capable of storing "store-generated values".
  • Loading branch information
lajones authored Jun 3, 2020
1 parent 923dd6e commit 3ff4d59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public virtual void ProcessModelFinalizing(
!exampleProperty.IsNullable).Builder;
concurrencyShadowPropertyBuilder
.HasColumnName(concurrencyColumnName)
.HasColumnType(exampleProperty.GetColumnType())
?.IsConcurrencyToken(true)
?.ValueGenerated(exampleProperty.ValueGenerated);
#pragma warning restore EF1001 // Internal EF Core API usage.
Expand Down Expand Up @@ -141,8 +142,7 @@ private void GetMappings(IConventionModel model,

foreach (var property in entityType.GetDeclaredProperties())
{
if (property.IsConcurrencyToken
&& (property.ValueGenerated & ValueGenerated.OnUpdate) != 0)
if (property.IsConcurrencyToken)
{
if (!concurrencyColumnsToProperties.TryGetValue(table, out var columnToProperties))
{
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore.Relational/Update/ModificationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ public bool TryPropagate(IProperty property, IUpdateEntry entry)
|| (entry.EntityState == EntityState.Modified && !entry.IsModified(property))
|| (entry.EntityState == EntityState.Added && Equals(_originalValue, entry.GetCurrentValue(property)))))
{
// Should be `entry.SetStoreGeneratedValue(property, _currentValue);` but see issue #21041
((InternalEntityEntry)entry)[property] = _currentValue;
entry.SetStoreGeneratedValue(property, _currentValue);

return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/PropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public static bool RequiresValueGenerator([NotNull] this IProperty property)
/// </summary>
public static bool MayBeStoreGenerated([NotNull] this IProperty property)
{
if (property.ValueGenerated != ValueGenerated.Never)
if (property.ValueGenerated != ValueGenerated.Never
|| property.IsConcurrencyToken)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ public virtual void Detects_duplicate_column_names_within_hierarchy_with_differe

VerifyError(
RelationalStrings.DuplicateColumnNameConcurrencyTokenMismatch(
nameof(Cat), nameof(Cat.Breed), nameof(Dog), nameof(Dog.Breed), nameof(Cat.Breed), nameof(Animal)), modelBuilder.Model);
nameof(Animal), "_TableSharingConcurrencyTokenConvention_Breed",
nameof(Dog), nameof(Dog.Breed),
nameof(Cat.Breed), nameof(Animal)),
modelBuilder.Model);
}

[ConditionalFact]
Expand Down

0 comments on commit 3ff4d59

Please sign in to comment.