From 210bcfe92b9ffa8fe439cfb4081d0ddd5b4bf025 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Fri, 4 May 2018 23:28:46 +0300 Subject: [PATCH] Fixed CriteriaImpl.Clone for Entity Join --- .../Async/Criteria/EntityJoinCriteriaTest.cs | 20 ++++++++++++++++++- .../Criteria/EntityJoinCriteriaTest.cs | 20 ++++++++++++++++++- src/NHibernate/Impl/CriteriaImpl.cs | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs b/src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs index bce97afd549..215c0fff9b2 100644 --- a/src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs +++ b/src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs @@ -47,7 +47,25 @@ public async Task CanJoinNotAssociatedEntityAsync() Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected"); } } - + + //GH1680 + [Test] + public void CanRowCountWithEntityJoinAsync() + { + using (var session = OpenSession()) + { + EntityComplex entityComplex = null; + EntityWithNoAssociation root = null; + var query = session.QueryOver(() => root) + .JoinEntityAlias(() => entityComplex, Restrictions.Where(() => root.Complex1Id == entityComplex.Id)); + + var rowCountQuery = query.ToRowCountQuery(); + int rowCount = 0; + Assert.DoesNotThrowAsync(async () => rowCount = await (rowCountQuery.SingleOrDefaultAsync()), "row count query should not throw exception"); + Assert.That(rowCount, Is.GreaterThan(0), "row count should be > 0"); + } + } + //check JoinEntityAlias - JoinAlias analog for entity join [Test] public async Task CanJoinNotAssociatedEntity_ExpressionAsync() diff --git a/src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs b/src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs index aab9ea3fa94..0ecebb750c6 100644 --- a/src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs +++ b/src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs @@ -36,7 +36,25 @@ public void CanJoinNotAssociatedEntity() Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected"); } } - + + //GH1680 + [Test] + public void CanRowCountWithEntityJoin() + { + using (var session = OpenSession()) + { + EntityComplex entityComplex = null; + EntityWithNoAssociation root = null; + var query = session.QueryOver(() => root) + .JoinEntityAlias(() => entityComplex, Restrictions.Where(() => root.Complex1Id == entityComplex.Id)); + + var rowCountQuery = query.ToRowCountQuery(); + int rowCount = 0; + Assert.DoesNotThrow(() => rowCount = rowCountQuery.SingleOrDefault(), "row count query should not throw exception"); + Assert.That(rowCount, Is.GreaterThan(0), "row count should be > 0"); + } + } + //check JoinEntityAlias - JoinAlias analog for entity join [Test] public void CanJoinNotAssociatedEntity_Expression() diff --git a/src/NHibernate/Impl/CriteriaImpl.cs b/src/NHibernate/Impl/CriteriaImpl.cs index eaee6f5b18a..5183aded695 100644 --- a/src/NHibernate/Impl/CriteriaImpl.cs +++ b/src/NHibernate/Impl/CriteriaImpl.cs @@ -594,7 +594,7 @@ private void CloneSubcriteria(CriteriaImpl clone) "Could not find parent for subcriteria in the previous subcriteria. If you see this error, it is a bug"); } Subcriteria clonedSubCriteria = - new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType, subcriteria.WithClause); + new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType, subcriteria.WithClause, subcriteria.JoinEntityName); clonedSubCriteria.SetLockMode(subcriteria.LockMode); newParents[subcriteria] = clonedSubCriteria; }