Query node as first child of Range node

39 views
Skip to first unread message

Andrew Brobston

unread,
Feb 23, 2016, 6:28:00 AM2/23/16
to nhibernate-development
I am running into some difficulties as I work on fixing NH-3845 via Pull Request #456, which I badly need fixed for a client project.  There is an additional test case that I would add to the fixture:


 
[Test]
 
public void SourceTypeWhenOfTypeAppliedToSelectIsCorrect()
 
{
     
using (ISession session = OpenSession())
     
using (session.BeginTransaction())
     
{
         
var entityQuery = session.Query<IMainEntity>();
         
var result =
             entityQuery
.Where(
                 m
=>
                     m
.Properties.OfType<IPropertyEntityC>()
                     
.Select(c => c.AnotherEntity)
                     
.OfType<AnotherEntity>()
                     
.Any(ae => ae.Text == "Another Entity Text")).ToList();
         
Assert.AreEqual(1, result.Count);
     
}
 
}


The test case fails, of course.  One of the reasons this issue is difficult to fix is that some part of the Linq provider keeps adding a Query node as the first child of a Range node.  None of the existing code, however, appears to support this scenario:

private static string GetClassName(IASTNode querySource)
{
   
switch (querySource.Type)
   
{
       
case HqlSqlWalker.IDENT:
           
return querySource.Text;
       
case HqlSqlWalker.DOT:
           
return BuildPath(querySource);
   
}

   
// TODO
   
throw new NotSupportedException();
}

HqlSqlWalker.g:
fromElement!
 
@init {
     
IASTNode fromElement = null;
 
}
 
// A simple class name, alias element.
 
: ^(RANGE p=path (a=ALIAS)? (pf=FETCH)? ) { fromElement = CreateFromElement($p.p, $p.tree, $a, $pf); }
   
-> {fromElement != null}? ^({fromElement})
   
->
 
| je=joinElement
   
-> //$je
 
// A from element created due to filter compilation
 
| fe=FILTER_ENTITY a3=ALIAS
   
-> ^({CreateFromFilterElement($fe,$a3)})
 
;

If I had to guess at the design philosophy of subqueries in the Linq provider, I would guess that subqueries in the FROM clause are supposed to be promoted to the outermost query.  I'm not sure of that, however, and it isn't clear to me how this goal is accomplished in all cases.

Could someone point me in the right direction?  I've tried allowing the query node to be the first child of the range node, but I'm not having any luck getting my solution to work.

Oskar Berggren

unread,
Feb 23, 2016, 11:28:25 AM2/23/16
to nhibernate-...@googlegroups.com
The HQL engine does not support subqueries in the FROM clause, and the LINQ provider has to work within this limitation.

/OSkar

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Brobston

unread,
Feb 23, 2016, 1:25:25 PM2/23/16
to nhibernate-development
That makes sense.  But, I guess I'm asking for alternatives to including subqueries in the FROM clause.  Is the idea that all subqueries are somehow promoted to the main query?  Is there some overarching "philosophy" I should be following when attempting to do so?
Reply all
Reply to author
Forward
0 new messages