Skip to content

Commit 0245389

Browse files
Fix component equality failure
Minimal fix for NH-3480
1 parent 5456d85 commit 0245389

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

src/NHibernate.Test/Async/NHSpecificTest/NH3480/Fixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public async Task TestAsync()
6868
var entity = await (result.SingleAsync());
6969

7070
await (NHibernateUtil.InitializeAsync(entity.Children));
71+
Assert.That(entity.Children, Has.Count.GreaterThan(0));
7172
}
7273
}
7374
}
7475
}
75-
}
76+
}

src/NHibernate.Test/NHSpecificTest/NH3480/Fixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public void Test()
5757
var entity = result.Single();
5858

5959
NHibernateUtil.Initialize(entity.Children);
60+
Assert.That(entity.Children, Has.Count.GreaterThan(0));
6061
}
6162
}
6263
}
6364
}
64-
}
65+
}

src/NHibernate/Type/ComponentType.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,10 @@ public override int Compare(object x, object y)
570570

571571
public override bool IsEqual(object x, object y)
572572
{
573-
if (x == y)
574-
{
575-
return true;
576-
}
577-
if (x == null || y == null)
578-
{
579-
return false;
580-
}
573+
var isEqualFast = IsEqualFast(x, y);
574+
if (isEqualFast.HasValue)
575+
return isEqualFast.Value;
576+
581577
object[] xvalues = GetPropertyValues(x);
582578
object[] yvalues = GetPropertyValues(y);
583579
for (int i = 0; i < propertySpan; i++)
@@ -592,14 +588,10 @@ public override bool IsEqual(object x, object y)
592588

593589
public override bool IsEqual(object x, object y, ISessionFactoryImplementor factory)
594590
{
595-
if (x == y)
596-
{
597-
return true;
598-
}
599-
if (x == null || y == null)
600-
{
601-
return false;
602-
}
591+
var isEqualFast = IsEqualFast(x, y);
592+
if (isEqualFast.HasValue)
593+
return isEqualFast.Value;
594+
603595
object[] xvalues = GetPropertyValues(x);
604596
object[] yvalues = GetPropertyValues(y);
605597
for (int i = 0; i < propertySpan; i++)
@@ -612,6 +604,24 @@ public override bool IsEqual(object x, object y, ISessionFactoryImplementor fact
612604
return true;
613605
}
614606

607+
private bool? IsEqualFast(object x, object y)
608+
{
609+
if (x == y)
610+
{
611+
return true;
612+
}
613+
if (x == null || y == null)
614+
{
615+
return false;
616+
}
617+
618+
var componentType = EntityMode == EntityMode.Poco ? ComponentTuplizer.MappedClass : typeof(IDictionary);
619+
if (!componentType.IsInstanceOfType(x) || !componentType.IsInstanceOfType(y))
620+
return false;
621+
622+
return null;
623+
}
624+
615625
public virtual bool IsMethodOf(MethodBase method)
616626
{
617627
return false;

0 commit comments

Comments
 (0)