Description
Trying to join two entities and select a projection each will in some cases results in a NotSupportedException
while being supported in other cases.
If the projection is defined in the from
clause of the query, the query can be compiled. Example:
var query =
from team in
session.Query<TeamEntity>()
.Select(team => new TeamModel
{
TeamId = team.Id,
Shortname = team.Shortname
})
join player in session.Query<PlayerEntity>()
on team.TeamId equals player.TeamId
select new PlayerModel
{
PlayerId = player.Id,
TeamId = team.TeamId,
Shortname = team.Shortname,
Name = player.Name
};
query.ToList();
The statement above compiles into the following SQL statement (generated names replaced):
select player.Player_Id, team.Team_Id, team.Shortname, player.Name
from DalTest_Team team, DalTest_Player player
where player.Team_Id=team.Team_Id
If the projection is defined in the join
clause of the query, the query cannot be compiled. Example:
var query =
from player in session.Query<PlayerEntity>()
join team in
session.Query<TeamEntity>()
.Select(team => new TeamModel
{
TeamId = team.Id,
Shortname = team.Shortname
})
on player.TeamId equals team.TeamId
select new PlayerModel
{
PlayerId = player.Id,
TeamId = team.TeamId,
Shortname = team.Shortname,
Name = player.Name
};
query.ToList();
We do not understand why there would be a difference whether the projection is part of the from
or part of the join
statement. Is there any technical reason for this behavior?
Is this a bug?
There is a fully functional unit test project in this GitHub repository. All required dependencies including SQLite can be restored using NuGet.
Original description
This issue was originally posted on StackOverflow with more details including a runnable test project. I did not get any community feedback within two weeks and therefore thinkt that this actually is a bug and try to report it here for clarification.
We experience an unexpected behavior of the NHibernate LINQ provider. We try to join two entities and select a projection each which sometimes results in a NotSupportedException.
Detailed description of the issue and runnable code example.
Please let me know if I should include the entire text in this GitHub issue as well or if you prefer the link the original post on StackOverflow.
Thank you for any feedback.