Uploaded image for project: 'NHibernate [Moved to GitHub]'
  1. NH-3044

Self-joined query with subquery and where - where applied to subquery rather than the external query

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 3.2.0.GA
    • Fix versions: 3.3.0.CR1
    • Components: Linq Provider
    • Labels:
      None
    • Sprint:

      Description

      I have the following query:

      var query = from log in _session.Query<Log>()
      where log == _session.Query<Log>()
      .OrderByDescending(l => l.DatePublished)
      .First(l => l.ServiceName == log.ServiceName)
      orderby log.ServiceName
      select log;

      The sql that gets generated looks like this:

      select log0_.Id as Id1_,
      log0_.DatePublished as DatePubl2_1_,
      log0_.ServiceName as ServiceN3_1_,
      log0_.Version as Version1_
      from Log log0_
      where log0_.Id = (select TOP (1) log1_.Id
      from Log log1_
      where log1_.ServiceName = log0_.ServiceName
      order by log1_.DatePublished desc,
      log0_.ServiceName asc);

      Notice the ordering from "orderby log.ServiceName" ends up being shoved into the subquery, which is wrong. The resulting set will not be sorted.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kkozmic k
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?