diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs new file mode 100644 index 00000000000..9d9444737a6 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Criterion; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH2330 +{ + using System.Threading.Tasks; + [TestFixture] + public class JoinedSubclassWithClauseFixtureAsync : TestCaseMappingByCode + { + private object _visit1Id; + private object _visit2Id; + + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + + mapper.Class(ca => + { + ca.Id(x => x.Id, map => map.Generator(Generators.Identity)); + ca.Property(x => x.Deleted); + ca.Property(x => x.FamilyName); + ca.Table("Node"); + ca.Abstract(true); + }); + + mapper.JoinedSubclass( + ca => + { + ca.Key(x => x.Column("FK_Node_ID")); + ca.Extends(typeof(Node)); + ca.Property(x => x.Deleted); + ca.Property(x => x.Login); + }); + + mapper.Class( + ca => + { + ca.Id(x => x.Id, map => map.Generator(Generators.Identity)); + ca.Property(x => x.Deleted); + ca.ManyToOne(x => x.PersonBase); + }); + + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } + + protected override void OnSetUp() + { + using (var arrangeSession = OpenSession()) + using (var tx = arrangeSession.BeginTransaction()) + { + var person = new PersonBase {Login = "dave", FamilyName = "grohl"}; + arrangeSession.Save(person); + _visit1Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person}); + _visit2Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person}); + arrangeSession.Flush(); + + tx.Commit(); + } + } + + protected override void OnTearDown() + { + using (var session = OpenSession()) + using (var transaction = session.BeginTransaction()) + { + session.Delete("from System.Object"); + + transaction.Commit(); + } + } + + [Test] + public async Task Join_InheritanceAsync() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + var results = (await (session + .CreateCriteria() + .CreateCriteria( + $"{nameof(UserEntityVisit.PersonBase)}", + "f", + SqlCommand.JoinType.LeftOuterJoin, + Restrictions.Eq("Deleted", false)) + .ListAsync())) + .Select(x => x.Id); + + Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,})); + } + } + + [Test] + public async Task Join_Inheritance_QueryOverAsync() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + PersonBase f = null; + var results = (await (session.QueryOver() + .JoinAlias( + x => x.PersonBase, + () => f, + SqlCommand.JoinType.LeftOuterJoin, + Restrictions.Where(() => f.Deleted == false)) + .ListAsync())) + .Select(x => x.Id); + + Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,})); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs b/src/NHibernate.Test/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs new file mode 100644 index 00000000000..7348a5da7a0 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH2330/JoinedSubclassWithClauseFixture.cs @@ -0,0 +1,114 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Criterion; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH2330 +{ + [TestFixture] + public class JoinedSubclassWithClauseFixture : TestCaseMappingByCode + { + private object _visit1Id; + private object _visit2Id; + + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + + mapper.Class(ca => + { + ca.Id(x => x.Id, map => map.Generator(Generators.Identity)); + ca.Property(x => x.Deleted); + ca.Property(x => x.FamilyName); + ca.Table("Node"); + ca.Abstract(true); + }); + + mapper.JoinedSubclass( + ca => + { + ca.Key(x => x.Column("FK_Node_ID")); + ca.Extends(typeof(Node)); + ca.Property(x => x.Deleted); + ca.Property(x => x.Login); + }); + + mapper.Class( + ca => + { + ca.Id(x => x.Id, map => map.Generator(Generators.Identity)); + ca.Property(x => x.Deleted); + ca.ManyToOne(x => x.PersonBase); + }); + + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } + + protected override void OnSetUp() + { + using (var arrangeSession = OpenSession()) + using (var tx = arrangeSession.BeginTransaction()) + { + var person = new PersonBase {Login = "dave", FamilyName = "grohl"}; + arrangeSession.Save(person); + _visit1Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person}); + _visit2Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person}); + arrangeSession.Flush(); + + tx.Commit(); + } + } + + protected override void OnTearDown() + { + using (var session = OpenSession()) + using (var transaction = session.BeginTransaction()) + { + session.Delete("from System.Object"); + + transaction.Commit(); + } + } + + [Test] + public void Join_Inheritance() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + var results = session + .CreateCriteria() + .CreateCriteria( + $"{nameof(UserEntityVisit.PersonBase)}", + "f", + SqlCommand.JoinType.LeftOuterJoin, + Restrictions.Eq("Deleted", false)) + .List() + .Select(x => x.Id); + + Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,})); + } + } + + [Test] + public void Join_Inheritance_QueryOver() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + PersonBase f = null; + var results = session.QueryOver() + .JoinAlias( + x => x.PersonBase, + () => f, + SqlCommand.JoinType.LeftOuterJoin, + Restrictions.Where(() => f.Deleted == false)) + .List() + .Select(x => x.Id); + + Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,})); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH2330/Node.cs b/src/NHibernate.Test/NHSpecificTest/GH2330/Node.cs new file mode 100644 index 00000000000..bad76be6d32 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH2330/Node.cs @@ -0,0 +1,26 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.GH2330 +{ + public abstract class Node + { + public virtual int Id { get; set; } + public virtual bool Deleted { get; set; } + public virtual string FamilyName { get; set; } + } + + [Serializable] + public class PersonBase : Node + { + public virtual string Login { get; set; } + public override bool Deleted { get; set; } + } + + [Serializable] + public class UserEntityVisit + { + public virtual int Id { get; set; } + public virtual bool Deleted { get; set; } + public virtual PersonBase PersonBase { get; set; } + } +}