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

LINQ query that contains .Any() produces invalid SQL

    Details

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

      Description

      I have a very simple entity CostItem.
      Here is my mapping:
      <?xml version="1.0" encoding="utf-8" ?>
      <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
      namespace="NHibernate.Test.NHSpecificTest.NH2911">
      <class name="CostItem" table="CostItem" >
      <id name="Id" access="nosetter.camelcase-underscore">
      <generator class="identity" />
      </id>
      <property name="Units" />
      </class>
      </hibernate-mapping>

      I am trying to write a LINQ query Q2 that returns all CostItem and exclude result set of another linq query Q1 .

      var Q1 = (from ci in session.Query<CostItem>()
      where ci.Id == 1
      select ci);

      var Q2 = (from ci in session.Query<CostItem>()
      where !Q1.Any(c => c.Id == ci.Id)
      select ci).ToArray();

      Q2 produces invalid SQL:

      select costitem0_.Id as Id0_,
      costitem0_.Units as Units0_
      from CostItem costitem0_
      where not
      (exists (select costitem1_.Id
      from CostItem costitem1_
      where costitem1_.Id=1
      and costitem1_.Id=costitem1_.Id)
      )

      It seems that and costitem1_.Id=costitem1_.Id is wrong

      should be costitem1_.Id=costitem0_.Id

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              maruseac ValentinM
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?