Skip to content

Commit 3f91650

Browse files
authored
Fix CheckInverseList without property comparer to call invalid overload (#688)
Closes #212 +semver:fix
1 parent 4f88b7a commit 3f91650

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using FluentNHibernate.Mapping;
4+
using FluentNHibernate.Testing.Cfg;
5+
using NUnit.Framework;
6+
7+
namespace FluentNHibernate.Testing.DomainModel;
8+
9+
public class UnidirectionalOneToManyTester
10+
{
11+
[SetUp]
12+
public void SetUp()
13+
{
14+
var properties = SQLiteFrameworkConfigurationFactory
15+
.CreateStandardConfiguration()
16+
.UseOuterJoin()
17+
.ShowSql()
18+
.InMemory()
19+
.ToProperties();
20+
21+
var model = new PersistenceModel();
22+
model.Add(typeof(OrderMap));
23+
model.Add(typeof(LineItemMap));
24+
_source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, model);
25+
_source.BuildSchema();
26+
}
27+
28+
ISessionSource _source;
29+
30+
[Test]
31+
public void ShouldHandleUnidirectionalCollections()
32+
{
33+
var order = new Order() { LineItems = new List<LineItem>() };
34+
order.LineItems.Add(new LineItem());
35+
new PersistenceSpecification<Order>(_source)
36+
/* NHibernate.PropertyValueException: not-null property references
37+
* a null or transient value LineItem._Order.LineItemsBackref */
38+
.CheckInverseList(o => o.LineItems, order.LineItems, i => i.Id)
39+
.VerifyTheMappings();
40+
}
41+
}
42+
43+
public class Order
44+
{
45+
public virtual Guid Id { get; set; }
46+
public virtual ICollection<LineItem> LineItems { get; set; }
47+
}
48+
49+
public class LineItem
50+
{
51+
public virtual Guid Id { get; set; }
52+
}
53+
54+
public class OrderMap : ClassMap<Order>
55+
{
56+
public OrderMap()
57+
{
58+
Id(x => x.Id).GeneratedBy.GuidComb();
59+
HasMany(x => x.LineItems)
60+
.Not.Inverse()
61+
.Not.KeyNullable()
62+
.Not.KeyUpdate()
63+
.Cascade.AllDeleteOrphan();
64+
}
65+
}
66+
67+
public class LineItemMap : ClassMap<LineItem>
68+
{
69+
public LineItemMap()
70+
{
71+
Id(x => x.Id).GeneratedBy.GuidComb();
72+
}
73+
}
74+

src/FluentNHibernate/Testing/PersistenceSpecificationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static PersistenceSpecification<T> CheckInverseList<T, TListElement>(this
166166
// Because of the params keyword, the compiler can select this overload
167167
// instead of the one above, even when no funcs are supplied in the method call.
168168
if (propertiesToCompare is null || propertiesToCompare.Length == 0)
169-
return spec.CheckList(expression, propertyValue, (IEqualityComparer)null);
169+
return spec.CheckInverseList(expression, propertyValue, (IEqualityComparer)null);
170170

171171
return spec.CheckInverseList(expression, propertyValue, new FuncEqualityComparer<TListElement>(propertiesToCompare));
172172
}

0 commit comments

Comments
 (0)