Skip to content

Commit d3f1323

Browse files
authored
Fix nullable entity comparison with null and implicit/cross joins (#2891)
1 parent febf050 commit d3f1323

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/NHibernate.Test/Async/Hql/EntityJoinHqlTest.cs

+6
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,16 @@ public async Task NullableEntityProjectionAsync()
344344
var withValidManyToOneList = await (session.Query<NullableOwner>().Where(x => x.ManyToOne != null).Select(x => new {x.Name, ManyToOneId = (Guid?) x.ManyToOne.Id}).ToListAsync());
345345
var withValidManyToOneList2 = await (session.CreateQuery("from NullableOwner ex where not ex.ManyToOne is null").ListAsync<NullableOwner>());
346346
var withNullManyToOneList = await (session.Query<NullableOwner>().Where(x => x.ManyToOne == null).ToListAsync());
347+
var withNullManyToOneJoinedList =
348+
await ((from x in session.Query<NullableOwner>()
349+
from x2 in session.Query<NullableOwner>()
350+
where x == x2 && x.ManyToOne == null && x.OneToOne.Name == null
351+
select x2).ToListAsync());
347352
Assert.That(fullList.Count, Is.EqualTo(2));
348353
Assert.That(withValidManyToOneList.Count, Is.EqualTo(0));
349354
Assert.That(withValidManyToOneList2.Count, Is.EqualTo(0));
350355
Assert.That(withNullManyToOneList.Count, Is.EqualTo(2));
356+
Assert.That(withNullManyToOneJoinedList.Count, Is.EqualTo(2));
351357
}
352358
}
353359

src/NHibernate.Test/Hql/EntityJoinHqlTest.cs

+6
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,16 @@ public void NullableEntityProjection()
332332
var withValidManyToOneList = session.Query<NullableOwner>().Where(x => x.ManyToOne != null).Select(x => new {x.Name, ManyToOneId = (Guid?) x.ManyToOne.Id}).ToList();
333333
var withValidManyToOneList2 = session.CreateQuery("from NullableOwner ex where not ex.ManyToOne is null").List<NullableOwner>();
334334
var withNullManyToOneList = session.Query<NullableOwner>().Where(x => x.ManyToOne == null).ToList();
335+
var withNullManyToOneJoinedList =
336+
(from x in session.Query<NullableOwner>()
337+
from x2 in session.Query<NullableOwner>()
338+
where x == x2 && x.ManyToOne == null && x.OneToOne.Name == null
339+
select x2).ToList();
335340
Assert.That(fullList.Count, Is.EqualTo(2));
336341
Assert.That(withValidManyToOneList.Count, Is.EqualTo(0));
337342
Assert.That(withValidManyToOneList2.Count, Is.EqualTo(0));
338343
Assert.That(withNullManyToOneList.Count, Is.EqualTo(2));
344+
Assert.That(withNullManyToOneJoinedList.Count, Is.EqualTo(2));
339345
}
340346
}
341347

src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,15 @@ protected virtual void FromFragmentSeparator(IASTNode a)
229229
}
230230
else
231231
{
232-
// these are just two unrelated table references
233-
Out(", ");
232+
if (right.JoinSequence?.IsThetaStyle == false && right.JoinSequence.JoinCount != 0)
233+
{
234+
Out(" ");
235+
}
236+
else
237+
{
238+
// these are just two unrelated table references
239+
Out(", ");
240+
}
234241
}
235242
}
236243

0 commit comments

Comments
 (0)