Repository: dotnet/efcore
File: src/EFCore.Relational/Update/Internal/ColumnAccessorsFactory.cs (C#)

Code before:
                ? (default, false)
                : modification.Value == null
                    ? (default, false)
                    : ((TColumn)modification.Value!, true);
        };

    private static Func<IReadOnlyModificationCommand, (TColumn, bool)> CreateOriginalValueGetter<TColumn>(IColumn column)
        => c =>
        {
            if (c.Entries.Count > 0)
            {
                var value = default(TColumn)!;
                var valueFound = false;
                for (var i = 0; i < c.Entries.Count; i++)
                {
                    var entry = c.Entries[i];
                    var property = column.FindColumnMapping(entry.EntityType)?.Property;
                    if (property == null)
                    {
                        continue;
                    }

                    if (entry.EntityState == EntityState.Added
                        && entry.SharedIdentityEntry != null)
                    {
                        entry = entry.SharedIdentityEntry;
                    }

                    var providerValue = entry.GetOriginalProviderValue(property);
                    if (providerValue == null)
                    {
                        return (value!, valueFound);
                    }

                    value = (TColumn)providerValue!;
                    valueFound = true;
                    if (entry.EntityState == EntityState.Unchanged
                        || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)))
                    {
                        return (value, valueFound);
                    }
                }

                return (value, valueFound);
            }

            var modification = c.ColumnModifications.FirstOrDefault(m => m.ColumnName == column.Name);
            return modification == null
                ? (default!, false)
                : modification.OriginalValue == null
                    ? (default!, false)

Review comment (performance):
After redirecting to SharedIdentityEntry, the property should be re-looked up if the EntityTypes are different, following the pattern in CommandBatchPreparer.cs lines 1005-1014. The current code uses the property from the original entry's EntityType, which may not be valid for the SharedIdentityEntry if they have different types.

Suggested fix:
```csharp
if (entry.EntityState == EntityState.Added
    && entry.SharedIdentityEntry != null)
{
    var sharedEntry = entry.SharedIdentityEntry;
    var sharedProperty = sharedEntry.EntityType == entry.EntityType
        ? property
        : column.FindColumnMapping(sharedEntry.EntityType)?.Property;
    
    if (sharedProperty != null)
    {
        entry = sharedEntry;
        property = sharedProperty;
    }
}
```

Then use `property` in the subsequent GetOriginalProviderValue call.
```suggestion
                        var sharedEntry = entry.SharedIdentityEntry;
                        var sharedProperty = sharedEntry.EntityType == entry.EntityType
                            ? property
                            : column.FindColumnMapping(sharedEntry.EntityType)?.Property;

                        if (sharedProperty != null)
                        {
                            entry = sharedEntry;
                            property = sharedProperty;
                        }
```

Code after:
    private static Func<IReadOnlyModificationCommand, (TColumn, bool)> CreateOriginalValueGetter<TColumn>(IColumn column)
        => c =>
        {
            if (c.Entries.Count > 0)
            {
                var value = default(TColumn)!;
                var valueFound = false;
                for (var i = 0; i < c.Entries.Count; i++)
                {
                    var entry = c.Entries[i];
                    if (entry.EntityState == EntityState.Added
                        && entry.SharedIdentityEntry != null)
                    {
                        entry = entry.SharedIdentityEntry;
                    }

                    var property = column.FindColumnMapping(entry.EntityType)?.Property;
                    if (property == null)
                    {
                        continue;
                    }

                    var providerValue = entry.GetOriginalProviderValue(property);
                    if (providerValue == null)
                    {
                        return (value!, valueFound);
                    }

                    value = (TColumn)providerValue!;
                    valueFound = true;
                    if (entry.EntityState == EntityState.Unchanged
                        || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)))
                    {
                        return (value, valueFound);
                    }
                }

                return (value, valueFound);
            }

            var modification = c.ColumnModifications.FirstOrDefault(m => m.ColumnName == column.Name);
            return modification == null
                ? (default!, false)
                : modification.OriginalValue == null
                    ? (default!, false)
                    : ((TColumn)modification.OriginalValue!, true);
        };
}