Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>()), "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()
Expand Down
20 changes: 19 additions & 1 deletion src/NHibernate.Test/Criteria/EntityJoinCriteriaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(), "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()
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Impl/CriteriaImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down