Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OriginalValues and GetDatabaseValues for shared entity entries #19328

Open
Tracked by #22954
ItsSmiffy opened this issue Dec 16, 2019 · 4 comments
Open
Tracked by #22954

Comments

@ItsSmiffy
Copy link

I'm in the process of creating an audit log for changed entities/properties but I cannot seem to get original values from an Owned Entity property once that Owned Entity has been replaced by a new instance.

Some of my Entities have properties which are Value Object / Owned Entities (and some of those have nested owned entities). I seem to have hit a blocker whereby I cannot retrieve the old value of an owned entity property once the owning Entity has replaced the owned entity with a new one.

The Owned Entity OriginalValues collection or the call to .GetDatabaseValues() returns the new Owned Entity instance, not the original one as is in the database (n.b. saveChanges has not yet been called).

It is possible to get the original values of an owned entity, even when the owned entity has been replaced by a new instance of that type?

EF Core version: 2.2.6
Database provider: Pomelo (v.2.2.6)
Target framework: .NET Framework 4.6
Operating system: Win 10
IDE: Visual Studio 2019 16.4.1

@ajcvickers
Copy link
Contributor

@ItsSmiffy The original values are not available because the original entity is marked as Deleted, while the new entity is marked as Added. However, due to the way owned entities are used it would be worthwhile to add support for getting original values this case. Putting this on the backlog to consider for a future release.

@HaisojYellams
Copy link

From the comment above, it sounds like when a Value Object (owned type) is replaced on an entity, the ChangeTracker should have two EntityEntries for that property: one for the old one (with an EntityState.Deleted state) and the new one (with an EntityState.Added state). Am I understanding that correctly?

In working with EF Core 5, I have not found this to be the case. That is, if I replace an existing Value Object with a new one, I only get an 'Added' entry in the change tracker - no 'Deleted' entry. Is this the intended behaviour?

@ajcvickers
Copy link
Contributor

@HaisojYellams Currently what you see is the intended behavior. That may change after this feature is implemented, but that is yet to be determined.

@Lobosque
Copy link

Our modeling relies heavily on owned entities and we are also being affected by this shortcoming.

@AndriySvyryd AndriySvyryd changed the title Cannot get original values of owned entity. Support OriginalValues and GetDatabaseValues for shared entity entries Jan 14, 2022
@ajcvickers ajcvickers self-assigned this Oct 21, 2022
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants