Skip to content

Entity Joins are not polymorphic in hql #2484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2020
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
8 changes: 8 additions & 0 deletions src/NHibernate.Test/Async/Linq/ByMethod/JoinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,13 @@ from o2 in db.Orders.Where(x => x.Freight > 50)
Assert.That(GetTotalOccurrences(sql, "inner join"), Is.EqualTo(useCrossJoin ? 0 : 1));
}
}

[Test]
public async Task CanJoinOnEntityWithSubclassesAsync()
{
var result = await ((from o in db.Animals
from o2 in db.Animals.Where(x => x.BodyWeight > 50)
select new {o, o2}).Take(1).ToListAsync());
}
}
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/Linq/ByMethod/JoinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,13 @@ from o2 in db.Orders.Where(x => x.Freight > 50)
Assert.That(GetTotalOccurrences(sql, "inner join"), Is.EqualTo(useCrossJoin ? 0 : 1));
}
}

[Test]
public void CanJoinOnEntityWithSubclasses()
{
var result = (from o in db.Animals
from o2 in db.Animals.Where(x => x.BodyWeight > 50)
select new {o, o2}).Take(1).ToList();
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate/Engine/JoinSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private bool IsIncluded(string alias)
return selector != null && selector.IncludeSubclasses(alias);
}

private void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable joinable, bool innerJoin)
private protected void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable joinable, bool innerJoin)
{
bool include = IsIncluded(alias);
joinFragment.AddJoins(joinable.FromJoinFragment(alias, innerJoin, include),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ internal override JoinFragment ToJoinFragment(
// on.Append(" and ").Append(filters);
// }
joinFragment.AddJoin(_tableName, _tableAlias, Array.Empty<string>(), Array.Empty<string>(), _joinType, on);
if (includeExtraJoins)
{
AddExtraJoins(joinFragment, _tableAlias, _entityType.GetAssociatedJoinable(Factory), _joinType == JoinType.InnerJoin);
}
return joinFragment;
}
}
Expand Down