diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
index 8b67ffc8015..29896d0e998 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
@@ -1257,28 +1257,7 @@ private void SetProperty(
{
if (value == null)
{
- if (EntityState != EntityState.Deleted
- && EntityState != EntityState.Detached)
- {
- _stateData.FlagProperty(propertyIndex, PropertyFlag.Null, isFlagged: true);
-
- if (setModified)
- {
- SetPropertyModified(
- asProperty, changeState: true, isModified: true,
- isConceptualNull: true);
- }
-
- if (!isCascadeDelete
- && StateManager.DeleteOrphansTiming == CascadeTiming.Immediate)
- {
- HandleConceptualNulls(
- StateManager.SensitiveLoggingEnabled,
- force: false,
- isCascadeDelete: false);
- }
- }
-
+ HandleNullForeignKey(asProperty, setModified, isCascadeDelete);
writeValue = false;
}
else
@@ -1377,6 +1356,40 @@ private void SetProperty(
}
}
+ ///
+ /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
+ /// the same compatibility standards as public APIs. It may be changed or removed without notice in
+ /// any release. You should only use it directly in your code with extreme caution and knowing that
+ /// doing so can result in application failures when updating to a new Entity Framework Core release.
+ ///
+ public void HandleNullForeignKey(
+ IProperty property,
+ bool setModified = false,
+ bool isCascadeDelete = false)
+ {
+ if (EntityState != EntityState.Deleted
+ && EntityState != EntityState.Detached)
+ {
+ _stateData.FlagProperty(property.GetIndex(), PropertyFlag.Null, isFlagged: true);
+
+ if (setModified)
+ {
+ SetPropertyModified(
+ property, changeState: true, isModified: true,
+ isConceptualNull: true);
+ }
+
+ if (!isCascadeDelete
+ && StateManager.DeleteOrphansTiming == CascadeTiming.Immediate)
+ {
+ HandleConceptualNulls(
+ StateManager.SensitiveLoggingEnabled,
+ force: false,
+ isCascadeDelete: false);
+ }
+ }
+ }
+
private static Func