Skip to content

Commit

Permalink
Avoid updating unchanged properties
Browse files Browse the repository at this point in the history
Fixes #30601
  • Loading branch information
AndriySvyryd committed Apr 6, 2023
1 parent 5d71afe commit 66fa9e6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class CommandBatchPreparer : ICommandBatchPreparer
private static readonly bool QuirkEnabled29647
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue29647", out var enabled) && enabled;

private static readonly bool QuirkEnabled30601
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue30601", out var enabled) && enabled;

private readonly int _minBatchSize;
private readonly bool _sensitiveLoggingEnabled;
private readonly bool _detailedErrorsEnabled;
Expand Down Expand Up @@ -983,6 +986,10 @@ private static bool IsModified(IReadOnlyList<IColumn> columns, IReadOnlyModifica
}

originalValue ??= entry.GetOriginalProviderValue(property);
if (!QuirkEnabled30601)
{
currentValue ??= entry.GetCurrentProviderValue(property);
}
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,44 @@ public virtual void Swap_filtered_unique_index_values()
});
}

[ConditionalFact]
public virtual void Update_non_indexed_values()
{
var productId1 = new Guid("984ade3c-2f7b-4651-a351-642e92ab7146");
var productId2 = new Guid("0edc9136-7eed-463b-9b97-bdb9648ab877");

ExecuteWithStrategyInTransaction(
context =>
{
var product1 = context.Products.Find(productId1)!;
var product2 = context.Products.Find(productId2)!;
product2.Price = product1.Price;
context.SaveChanges();
},
context =>
{
var product1 = new Product { Id = productId1, Name = "", Price = 1.49M };
var product2 = new Product { Id = productId2, Name = "", Price = 1.49M };
context.Attach(product1).Property(p => p.DependentId).IsModified = true;
context.Attach(product2).Property(p => p.DependentId).IsModified = true;
context.SaveChanges();
},
context =>
{
var product1 = context.Products.Find(productId1)!;
var product2 = context.Products.Find(productId2)!;
Assert.Equal(1.49M, product1.Price);
Assert.Null(product1.DependentId);
Assert.Equal(1.49M, product2.Price);
Assert.Null(product2.DependentId);
});
}

[ConditionalFact]
public abstract void Identifiers_are_generated_correctly();

Expand Down

0 comments on commit 66fa9e6

Please sign in to comment.