Skip to content

Commit 1df24c6

Browse files
bahusoidfredericDelaporte
authored andcommitted
Entity Joins are not polymorphic
1 parent 3e0a744 commit 1df24c6

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/NHibernate.Test/Async/Linq/ByMethod/JoinTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,13 @@ from o2 in db.Orders.Where(x => x.Freight > 50)
140140
Assert.That(GetTotalOccurrences(sql, "inner join"), Is.EqualTo(useCrossJoin ? 0 : 1));
141141
}
142142
}
143+
144+
[Test]
145+
public async Task CanJoinOnEntityWithSubclassesAsync()
146+
{
147+
var result = await ((from o in db.Animals
148+
from o2 in db.Animals.Where(x => x.BodyWeight > 50)
149+
select new {o, o2}).Take(1).ToListAsync());
150+
}
143151
}
144152
}

src/NHibernate.Test/Linq/ByMethod/JoinTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,13 @@ from o2 in db.Orders.Where(x => x.Freight > 50)
129129
Assert.That(GetTotalOccurrences(sql, "inner join"), Is.EqualTo(useCrossJoin ? 0 : 1));
130130
}
131131
}
132+
133+
[Test]
134+
public void CanJoinOnEntityWithSubclasses()
135+
{
136+
var result = (from o in db.Animals
137+
from o2 in db.Animals.Where(x => x.BodyWeight > 50)
138+
select new {o, o2}).Take(1).ToList();
139+
}
132140
}
133141
}

src/NHibernate/Engine/JoinSequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private bool IsIncluded(string alias)
249249
return selector != null && selector.IncludeSubclasses(alias);
250250
}
251251

252-
private void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable joinable, bool innerJoin)
252+
private protected void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable joinable, bool innerJoin)
253253
{
254254
bool include = IsIncluded(alias);
255255
joinFragment.AddJoins(joinable.FromJoinFragment(alias, innerJoin, include),

src/NHibernate/Hql/Ast/ANTLR/Tree/EntityJoinJoinSequenceImpl.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ internal override JoinFragment ToJoinFragment(
4141
// on.Append(" and ").Append(filters);
4242
// }
4343
joinFragment.AddJoin(_tableName, _tableAlias, Array.Empty<string>(), Array.Empty<string>(), _joinType, on);
44+
if (includeExtraJoins)
45+
{
46+
AddExtraJoins(joinFragment, _tableAlias, _entityType.GetAssociatedJoinable(Factory), _joinType == JoinType.InnerJoin);
47+
}
4448
return joinFragment;
4549
}
4650
}

0 commit comments

Comments
 (0)