From my tests (if correct), it seems that the ABP framework repository always saves even if none of the entity's properties have been changed. By default, EF Core doesn't save unchanged entities. Am I wrong? Is it possible that LastModificationTime handling causes this behavior?
Thanks, Fabrizio
4 Answer(s)
-
0
Hi @Fabrizio
Your observation is correct if the update goes through
Repository.Update/UpdateAsync(entity)in ASP.NET Boilerplate's EF Core integration.In that path, ABP attaches the entity and explicitly sets its state to
Modified, so EF Core treats it as an update even if no business property has actually changed.So you are not wrong about EF Core itself: by default, EF Core does not send an UPDATE for an unchanged tracked entity. The difference here is that ABP's repository
Updatemethod forces the modified state.Regarding
LastModificationTime: it is not what initially makes the entity modified. ABP setsLastModificationTimeduringSaveChanges, but only for entities that are already inModifiedstate. So it is more a consequence of the forced update path than the root cause.If the entity is first loaded/tracked and then saved without calling
Repository.Update, EF Core's normal change tracking should apply, and no UPDATE should be sent when nothing has changed.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @oguzhanagir, thanks for the explanation.
About: "In that path, ABP attaches the entity and explicitly sets its state to Modified, so EF Core treats it as an update even if no business property has actually changed."
Currently, I'm managing manually the unchanged entities. Do you think it's possible to plan the implementation of this feature? Perhaps with a specific setting.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @Fabrizio,
Yes, this can be considered as an enhancement request.
Currently, ASP.NET Boilerplate does not provide a built-in setting to make
Repository.Update/UpdateAsync(entity)skip the database update when the entity has no actual property changes. The EF Core repository implementation intentionally marks the entity asModified, so changing this default behavior would be a breaking behavioral change for existing applications.If we implement such a feature, it would most likely need to be opt-in, for example through a configuration setting. It also needs careful evaluation because it may affect detached entity updates, audit fields such as
LastModificationTime, entity history, concurrency handling, and owned entity changes.For now, the recommended approach is still:
- If the entity is already loaded/tracked, modify its properties directly and let EF Core change tracking decide whether an update is needed.
- Avoid calling
Repository.Update/UpdateAsyncwhen you want EF Core’s normal unchanged-entity behavior. - Continue using manual checks/custom repository logic if you specifically need to skip forced updates for detached entities.
We will share this with the team as a possible optional improvement; for now, we can plan this development for the next version.
Thank you.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @oguzhanagir, I completely agree with you, this new feature need to be carefully evaluated and managed by configuration in order to avoid breaking changes. In the meanwhile, I continue to manage manually the unchanged entities.
I hope to see this feature soon :-)
Thank you
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)