-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CheckInverseList without property comparer to call invalid overlo…
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/FluentNHibernate.Testing/DomainModel/UnidirectionalOneToManyTester.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters