Skip to content

Commit

Permalink
InMemoryTable: Make IsConcurrencyConflict() method more readable (dot…
Browse files Browse the repository at this point in the history
  • Loading branch information
y0ung3r authored and roji committed Apr 22, 2024
1 parent fa0973f commit 6c5cf10
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs
Expand Up @@ -229,29 +229,32 @@ public virtual void Delete(IUpdateEntry entry, IDiagnosticsLogger<DbLoggerCatego
object? rowValue,
Dictionary<IProperty, object?> concurrencyConflicts)
{
if (property.IsConcurrencyToken)
if (!property.IsConcurrencyToken)
{
var comparer = property.GetKeyValueComparer();
var originalValue = entry.GetOriginalValue(property);
return false;
}

var converter = property.GetValueConverter()
?? property.FindTypeMapping()?.Converter;
var comparer = property.GetKeyValueComparer()
?? StructuralComparisons.StructuralEqualityComparer;

if (converter != null)
{
rowValue = converter.ConvertFromProvider(rowValue);
}
var originalValue = entry.GetOriginalValue(property);

if ((comparer != null && !comparer.Equals(rowValue, originalValue))
|| (comparer == null && !StructuralComparisons.StructuralEqualityComparer.Equals(rowValue, originalValue)))
{
concurrencyConflicts.Add(property, rowValue);
var converter = property.GetValueConverter()
?? property.FindTypeMapping()?.Converter;

return true;
}
if (converter != null)
{
rowValue = converter.ConvertFromProvider(rowValue);
}

return false;
if (comparer.Equals(rowValue, originalValue))
{
return false;
}

concurrencyConflicts.Add(property, rowValue);

return true;
}

/// <summary>
Expand Down

0 comments on commit 6c5cf10

Please sign in to comment.