Created
April 25, 2020 01:09
-
-
Save markdchurchill/3c6e5104e1afb407a562752d19f74c84 to your computer and use it in GitHub Desktop.
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
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using NUnit.Framework; | |
using NHibernate; | |
using NHibernate.Cfg; | |
using NHibernate.Cfg.MappingSchema; | |
using NHibernate.Dialect; | |
using NHibernate.Driver; | |
using NHibernate.Mapping.ByCode; | |
namespace NHBug | |
{ | |
class Parent | |
{ | |
public virtual int FooId { get; set; } | |
public virtual IList<Child> Children { get; set; } | |
} | |
class Child | |
{ | |
public virtual int ChildId { get; set; } | |
public virtual Parent Parent { get; set; } | |
} | |
public class Tests | |
{ | |
[TestCase("customcolumnname")] | |
[TestCase("parent2_key")] | |
[TestCase("parent_key")] | |
[TestCase(null)] | |
public void Test1(string item) | |
{ | |
var mapper = new ModelMapper(); | |
mapper.Class<Child>(m => | |
{ | |
m.Id(c => c.ChildId, x => x.Generator(Generators.Native)); | |
m.ManyToOne(c => c.Parent, x => | |
{ | |
if (item != null) x.Column(item); | |
}); | |
}); | |
mapper.Class<Parent>(m => | |
{ | |
m.Id(c => c.FooId, x => x.Generator(Generators.Native)); | |
m.Set(c => c.Children, | |
bpm => | |
{ | |
bpm.Inverse(true); | |
if(item != null) bpm.Key(k => k.Column(item)); | |
}, | |
cer => { cer.OneToMany(); }); | |
}); | |
var mapping = mapper.CompileMappingFor(new[] {typeof(Parent), typeof(Child)}); | |
Assert.AreEqual(item ?? "Parent", mapping.RootClasses.Single(c => c.name == "Parent").Properties.OfType<HbmSet>().Single(p => p.Name == "Children").Key.column1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment