Skip to content

Commit 52ef196

Browse files
committed
Handle null in oldElements
1 parent f69c691 commit 52ef196

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/NHibernate/Async/Collection/AbstractPersistentCollection.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,18 @@ protected virtual async Task<ICollection> GetOrphansAsync(ICollection oldElement
193193
}
194194

195195
List<object> res = new List<object>();
196-
// oldElements may contain new elements in some cases
196+
// oldElements may contain new elements (one case when session.Save is called on new object with list)
197197
foreach (object old in oldElements)
198198
{
199-
var id = persister.GetIdentifier(old);
200-
if (id != null)
199+
if (old != null)
201200
{
202-
if (!currentObjects.Contains(id) && await (ForeignKeys.IsNotTransientSlowAsync(persister.EntityName, old, Session, cancellationToken)).ConfigureAwait(false))
201+
var id = persister.GetIdentifier(old);
202+
if (id != null)
203203
{
204-
res.Add(old);
204+
if (!currentObjects.Contains(id) && await (ForeignKeys.IsNotTransientSlowAsync(persister.EntityName, old, Session, cancellationToken)).ConfigureAwait(false))
205+
{
206+
res.Add(old);
207+
}
205208
}
206209
}
207210
}

src/NHibernate/Collection/AbstractPersistentCollection.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,18 @@ protected virtual ICollection GetOrphans(ICollection oldElements, ICollection cu
735735
}
736736

737737
List<object> res = new List<object>();
738-
// oldElements may contain new elements in some cases
738+
// oldElements may contain new elements (one case when session.Save is called on new object with list)
739739
foreach (object old in oldElements)
740740
{
741-
var id = persister.GetIdentifier(old);
742-
if (id != null)
741+
if (old != null)
743742
{
744-
if (!currentObjects.Contains(id) && ForeignKeys.IsNotTransientSlow(persister.EntityName, old, Session))
743+
var id = persister.GetIdentifier(old);
744+
if (id != null)
745745
{
746-
res.Add(old);
746+
if (!currentObjects.Contains(id) && ForeignKeys.IsNotTransientSlow(persister.EntityName, old, Session))
747+
{
748+
res.Add(old);
749+
}
747750
}
748751
}
749752
}

0 commit comments

Comments
 (0)