Skip to content

Commit e87efc6

Browse files
bahusoidfredericDelaporte
authored andcommitted
Fixed CriteriaImpl.Clone for Entity Join
1 parent a9cab57 commit e87efc6

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,25 @@ public async Task CanJoinNotAssociatedEntityAsync()
4747
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
4848
}
4949
}
50-
50+
51+
//GH1680
52+
[Test]
53+
public void CanRowCountWithEntityJoinAsync()
54+
{
55+
using (var session = OpenSession())
56+
{
57+
EntityComplex entityComplex = null;
58+
EntityWithNoAssociation root = null;
59+
var query = session.QueryOver(() => root)
60+
.JoinEntityAlias(() => entityComplex, Restrictions.Where(() => root.Complex1Id == entityComplex.Id));
61+
62+
var rowCountQuery = query.ToRowCountQuery();
63+
int rowCount = 0;
64+
Assert.DoesNotThrowAsync(async () => rowCount = await (rowCountQuery.SingleOrDefaultAsync<int>()), "row count query should not throw exception");
65+
Assert.That(rowCount, Is.GreaterThan(0), "row count should be > 0");
66+
}
67+
}
68+
5169
//check JoinEntityAlias - JoinAlias analog for entity join
5270
[Test]
5371
public async Task CanJoinNotAssociatedEntity_ExpressionAsync()

src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,25 @@ public void CanJoinNotAssociatedEntity()
3636
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
3737
}
3838
}
39-
39+
40+
//GH1680
41+
[Test]
42+
public void CanRowCountWithEntityJoin()
43+
{
44+
using (var session = OpenSession())
45+
{
46+
EntityComplex entityComplex = null;
47+
EntityWithNoAssociation root = null;
48+
var query = session.QueryOver(() => root)
49+
.JoinEntityAlias(() => entityComplex, Restrictions.Where(() => root.Complex1Id == entityComplex.Id));
50+
51+
var rowCountQuery = query.ToRowCountQuery();
52+
int rowCount = 0;
53+
Assert.DoesNotThrow(() => rowCount = rowCountQuery.SingleOrDefault<int>(), "row count query should not throw exception");
54+
Assert.That(rowCount, Is.GreaterThan(0), "row count should be > 0");
55+
}
56+
}
57+
4058
//check JoinEntityAlias - JoinAlias analog for entity join
4159
[Test]
4260
public void CanJoinNotAssociatedEntity_Expression()

src/NHibernate/Impl/CriteriaImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ private void CloneSubcriteria(CriteriaImpl clone)
594594
"Could not find parent for subcriteria in the previous subcriteria. If you see this error, it is a bug");
595595
}
596596
Subcriteria clonedSubCriteria =
597-
new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType, subcriteria.WithClause);
597+
new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType, subcriteria.WithClause, subcriteria.JoinEntityName);
598598
clonedSubCriteria.SetLockMode(subcriteria.LockMode);
599599
newParents[subcriteria] = clonedSubCriteria;
600600
}

0 commit comments

Comments
 (0)