Support OriginalValues and GetDatabaseValues for shared entity entries

Open
#19,328 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
database

Research direction

Start by reproducing the owned-entity replacement scenario with EF Core 2.2.6 and the Pomelo 2.2.6 provider, focusing on OriginalValues and GetDatabaseValues before SaveChanges. Done means both APIs expose the persisted original owned-entity values rather than the replacement instance.

Written by the indexing model from the issue text.

Description

area-change-tracking customer-reported needs-design

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

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.