From 27d05cc0745b35101c0b849da09669fc0ae49dea Mon Sep 17 00:00:00 2001 From: Christian Crowhurst Date: Wed, 17 May 2023 09:19:54 +0100 Subject: [PATCH] Ensure only modified properties are marked as modified (partial fix). See issue: https://github.com/Breeze/breeze.server.net/issues/188 --- DotNet/Breeze.Persistence.EFCore/EFPersistenceManager.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DotNet/Breeze.Persistence.EFCore/EFPersistenceManager.cs b/DotNet/Breeze.Persistence.EFCore/EFPersistenceManager.cs index 0ff2b0e4..bd7ec049 100644 --- a/DotNet/Breeze.Persistence.EFCore/EFPersistenceManager.cs +++ b/DotNet/Breeze.Persistence.EFCore/EFPersistenceManager.cs @@ -370,12 +370,14 @@ private EntityEntry HandleModified(EFEntityInfo entityInfo) { // Do NOT change this to EntityState.Modified because this will cause the entire record to update. entry.State = Microsoft.EntityFrameworkCore.EntityState.Unchanged; + // TODO: modify UpdateOriginalValues so that it mark as modified the changed properties of complex (aka owned) + // entities. Once modified remove the call to MarkOwnedChildren below // updating the original values is necessary under certain conditions when we change a foreign key field // because the before value is used to determine ordering. UpdateOriginalValues(entry, entityInfo); // SetModified(entry, entityInfo.ForceUpdate); - MarkEntryAndOwnedChildren(entry, Microsoft.EntityFrameworkCore.EntityState.Modified); + MarkOwnedChildren(entry, Microsoft.EntityFrameworkCore.EntityState.Modified); return entry; @@ -383,6 +385,10 @@ private EntityEntry HandleModified(EFEntityInfo entityInfo) { private void MarkEntryAndOwnedChildren(EntityEntry entry, Microsoft.EntityFrameworkCore.EntityState state ) { entry.State = state; + MarkOwnedChildren(entry, state); + } + + private void MarkOwnedChildren(EntityEntry entry, Microsoft.EntityFrameworkCore.EntityState state ) { // Handle owned entities - ( complex types). var ownedNavs = entry.Navigations.Where(n => n.Metadata.TargetEntityType.IsOwned());