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

subselect in LINQ query with Contains clause produces wrong SQL

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.0
    • Fix Version/s: 3.3.0.CR1
    • Component/s: Linq Provider
    • Labels:
      None
    • Sprint:

      Description

      I was trying to execute the following query

      return (from foo in _session.Query<Foo>()
      where (from personBar in _session.Query<PersonBars>()
      where personBar.Person.Id == _personId
      select personBar.Bar).Contains(foo.Bar)
      orderby foo.FooNumber
      select new SomeProjection(
      foo.Id,
      foo.A,
      foo.B,
      foo.Bar.Id,
      foo.Bar.Description)).ToList();

      basically the goal was to get all Foos with Bar that given user of the app has Bar for too.

      now the part of the SQL generated that has a bug in it looks kind of like this (sorry for obscuring it):

      where some clauses
      and (exists (select bar_.ID
      from PERSON_BAR pb
      joins to bar
      where some other clauses here
      and pb.ID = foo0_.BAR_ID))

      Notice the last line which should say

      pb.BAR_ID = foo0.BAR_ID
      that's the bug.

      Hope that helps.

        Attachments

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Who's Looking?