Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CheckInverseList without property comparer to call invalid overload #688

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using FluentNHibernate.Mapping;
using FluentNHibernate.Testing.Cfg;
using NUnit.Framework;

namespace FluentNHibernate.Testing.DomainModel;

public class UnidirectionalOneToManyTester
{
[SetUp]
public void SetUp()
{
var properties = SQLiteFrameworkConfigurationFactory
.CreateStandardConfiguration()
.UseOuterJoin()
.ShowSql()
.InMemory()
.ToProperties();

var model = new PersistenceModel();
model.Add(typeof(OrderMap));
model.Add(typeof(LineItemMap));
_source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, model);
_source.BuildSchema();
}

ISessionSource _source;

[Test]
public void ShouldHandleUnidirectionalCollections()
{
var order = new Order() { LineItems = new List<LineItem>() };
order.LineItems.Add(new LineItem());
new PersistenceSpecification<Order>(_source)
/* NHibernate.PropertyValueException: not-null property references
* a null or transient value LineItem._Order.LineItemsBackref */
.CheckInverseList(o => o.LineItems, order.LineItems, i => i.Id)
.VerifyTheMappings();
}
}

public class Order
{
public virtual Guid Id { get; set; }
public virtual ICollection<LineItem> LineItems { get; set; }
}

public class LineItem
{
public virtual Guid Id { get; set; }
}

public class OrderMap : ClassMap<Order>
{
public OrderMap()
{
Id(x => x.Id).GeneratedBy.GuidComb();
HasMany(x => x.LineItems)
.Not.Inverse()
.Not.KeyNullable()
.Not.KeyUpdate()
.Cascade.AllDeleteOrphan();
}
}

public class LineItemMap : ClassMap<LineItem>
{
public LineItemMap()
{
Id(x => x.Id).GeneratedBy.GuidComb();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static PersistenceSpecification<T> CheckInverseList<T, TListElement>(this
// Because of the params keyword, the compiler can select this overload
// instead of the one above, even when no funcs are supplied in the method call.
if (propertiesToCompare is null || propertiesToCompare.Length == 0)
return spec.CheckList(expression, propertyValue, (IEqualityComparer)null);
return spec.CheckInverseList(expression, propertyValue, (IEqualityComparer)null);

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