Skip to content

Commit 3f1b305

Browse files
Handle more explicitly a potential error case
1 parent 0c78505 commit 3f1b305

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/NHibernate/Action/EntityInsertAction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public override void Execute()
4949
// else inserted the same pk first, the insert would fail
5050
if (!veto)
5151
{
52-
if (id is DelayedPostInsertIdentifier delayed && delayed.ActualId != null)
52+
if (id is DelayedPostInsertIdentifier delayed)
5353
{
5454
wasDelayed = true;
55-
id = delayed.ActualId;
55+
id = delayed.ActualId ??
56+
throw new InvalidOperationException(
57+
$"The delayed foreign identifier {delayed} has not been resolved before insertion of a {instance}");
5658
}
5759
persister.Insert(id, State, instance, Session);
5860

src/NHibernate/Async/Action/EntityInsertAction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public override async Task ExecuteAsync(CancellationToken cancellationToken)
4545
// else inserted the same pk first, the insert would fail
4646
if (!veto)
4747
{
48-
if (id is DelayedPostInsertIdentifier delayed && delayed.ActualId != null)
48+
if (id is DelayedPostInsertIdentifier delayed)
4949
{
5050
wasDelayed = true;
51-
id = delayed.ActualId;
51+
id = delayed.ActualId ??
52+
throw new InvalidOperationException(
53+
$"The delayed foreign identifier {delayed} has not been resolved before insertion of a {instance}");
5254
}
5355
await (persister.InsertAsync(id, State, instance, Session, cancellationToken)).ConfigureAwait(false);
5456

0 commit comments

Comments
 (0)