LINQ query that contains .Any() produces invalid SQL
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
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