Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate: Double nested subqueries and "Could not find a matching criteria info provider..."
    primarykey
    data
    text
    <p>I am having trouble working out how to get the following sql into an NHibernate ICriteria:</p> <pre><code>select * from Contract contract_outer where exists ( select 1 from RequiredDocRules where not exists ( select 1 from Contract contract_inner inner join ContractDocs contractDocs on cDocs.ContractId = c_inner.Id inner join Doc doc doc.Id = contractDocs.DocId where contract_inner.Id = contract_outer.Id and doc.Type = RequiredDocRules.DocType) ) and RequiredDocRules.ContractType = contract_outer.Type ) </code></pre> <p>Basically, the query is saying "Show me contracts that are missing required documents, based on the rules for this type of contract".</p> <p>The CreateCriteria looks like this:</p> <pre><code>var subqueryB = DetachedCriteria.For&lt;Contract&gt;("contract_inner") .CreateAlias("contract_inner.Docs", "doc") .Add(Restrictions.EqProperty("doc.Type", "rule.DocType")) .Add(Restrictions.EqProperty("contract_inner.Id", "contract_outer.Id") .SetProjection(Projections.Id()); var subqueryA = DetachedCriteria.For&lt;RequiredDocRule&gt;("rule") .Add(Restriction.EqProperty("rule.ContractType", "contract_outer.Type")) .Add(Subqueries.NotExists(subqueryB)) .SetProjection(Projections.Id()); return Session.CreateCriteria&lt;Contract&gt;("contract_outer") .Add(Subqueries.Exists(subqueryA)) .List&lt;Contract&gt;(); </code></pre> <p>This above code throws the following obscure exception:</p> <blockquote> <p>Could not find a matching criteria info provider to: contract_inner.Id = contract_outer.Id and doc.Type = rule.DocType</p> </blockquote> <p>I've narrowed the issue down to the "contract_inner.Id = contract_outer.Id" restriction. Maybe it is having trouble traversing up through two layers of subqueries?</p> <p>I am using NHibernate 2.1 btw.</p> <p>I seem to be the only person getting this exception - if you google for the exception message another one of my Stackoverflow posts comes up number one. This question is similar, but different. So frustrating!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload