Skip to content

Commit 53e12b9

Browse files
committed
async regen
1 parent 1f77db9 commit 53e12b9

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ public async Task CanJoinNotAssociatedEntityAsync()
4848
}
4949
}
5050

51+
//check JoinEntityAlias - JoinAlias analog for entity join
52+
[Test]
53+
public async Task CanJoinNotAssociatedEntity_ExpressionAsync()
54+
{
55+
using (var sqlLog = new SqlLogSpy())
56+
using (var session = OpenSession())
57+
{
58+
EntityComplex entityComplex = null;
59+
EntityWithNoAssociation root = null;
60+
root = await (session.QueryOver(() => root)
61+
.JoinEntityAlias(() => entityComplex, () => root.Complex1Id == entityComplex.Id).Take(1)
62+
.SingleOrDefaultAsync());
63+
entityComplex = await (session.LoadAsync<EntityComplex>(root.Complex1Id));
64+
65+
Assert.That(NHibernateUtil.IsInitialized(entityComplex), Is.True);
66+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
67+
}
68+
}
69+
5170
//check JoinEntityQueryOver - JoinQueryOver analog for entity join
5271
[Test]
5372
public async Task CanJoinEntityQueryOverAsync()
@@ -254,6 +273,61 @@ public async Task EntityJoinForCustomEntityNameAsync()
254273
}
255274
}
256275

276+
[Test]
277+
public async Task EntityJoinFoSubquery_JoinEntityAliasAsync()
278+
{
279+
using (var sqlLog = new SqlLogSpy())
280+
using (var session = OpenSession())
281+
{
282+
EntityComplex ej = null;
283+
EntityWithNoAssociation root = null;
284+
285+
EntityComplex ejSub = null;
286+
EntityWithNoAssociation rootSub = null;
287+
288+
var subquery = QueryOver.Of<EntityWithNoAssociation>(() => rootSub)
289+
.JoinEntityAlias(() => ejSub, () => rootSub.Complex1Id == ejSub.Id)
290+
.Where(r => ejSub.Name == ej.Name)
291+
.Select(x => ejSub.Id);
292+
293+
root = await (session.QueryOver(() => root)
294+
.JoinEntityAlias(() => ej, Restrictions.Where(() => root.Complex1Id == ej.Id))
295+
.WithSubquery.WhereExists(subquery)
296+
.SingleOrDefaultAsync());
297+
ej = await (session.LoadAsync<EntityComplex>(root.Complex1Id));
298+
299+
Assert.That(NHibernateUtil.IsInitialized(ej), Is.True);
300+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
301+
}
302+
}
303+
304+
[Test]
305+
public async Task EntityJoinFoSubquery_JoinQueryOverAsync()
306+
{
307+
using (var sqlLog = new SqlLogSpy())
308+
using (var session = OpenSession())
309+
{
310+
EntityComplex ej = null;
311+
EntityWithNoAssociation root = null;
312+
313+
EntityComplex ejSub = null;
314+
EntityWithNoAssociation rootSub = null;
315+
316+
var subquery = QueryOver.Of<EntityWithNoAssociation>(() => rootSub)
317+
.JoinEntityQueryOver(() => ejSub, () => rootSub.Complex1Id == ejSub.Id)
318+
.Where(x => x.Name == ej.Name)
319+
.Select(x => ejSub.Id);
320+
321+
root = await (session.QueryOver(() => root)
322+
.JoinEntityAlias(() => ej, Restrictions.Where(() => root.Complex1Id == ej.Id))
323+
.WithSubquery.WhereExists(subquery)
324+
.SingleOrDefaultAsync());
325+
ej = await (session.LoadAsync<EntityComplex>(root.Complex1Id));
326+
327+
Assert.That(NHibernateUtil.IsInitialized(ej), Is.True);
328+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
329+
}
330+
}
257331
#region Test Setup
258332

259333
protected override HbmMapping GetMappings()

src/NHibernate/Loader/OuterJoinableAssociation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public void AddManyToManyJoin(JoinFragment outerjoin, IQueryableCollection colle
156156
string manyToManyFilter = collection.GetManyToManyFilterFragment(rhsAlias, enabledFilters);
157157
SqlString condition = string.Empty.Equals(manyToManyFilter)
158158
? on
159-
: SqlStringHelper.IsEmpty(on) ? new SqlString(manyToManyFilter) :
159+
: SqlStringHelper.IsEmpty(on) ? new SqlString(manyToManyFilter) :
160160
on.Append(" and ").Append(manyToManyFilter);
161161

162162
outerjoin.AddJoin(joinable.TableName, rhsAlias, lhsColumns, rhsColumns, joinType, condition);
163163
outerjoin.AddJoins(joinable.FromJoinFragment(rhsAlias, false, true),
164164
joinable.WhereJoinFragment(rhsAlias, false, true));
165165
}
166166
}
167-
}
167+
}

src/NHibernate/SqlCommand/ANSIJoinFragment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using NHibernate.Linq;
21
using NHibernate.Util;
32

43
namespace NHibernate.SqlCommand

0 commit comments

Comments
 (0)