Note that there are some explanatory texts on larger screens.

plurals
  1. POnHibernate Mapping/Query problem
    text
    copied!<pre><code> // Request.hbm.xml &lt;many-to-one name="Grant" class="Grant" column="GrantId" lazy="false"/&gt; // Grant.hbm.xml &lt;set name="requests" table="Request" generic="true"&gt; &lt;key column="GrantId" /&gt; &lt;one-to-many class="Request"/&gt; &lt;/set&gt; </code></pre> <p>The mapping works for everything else that uses the Grant property of Request. (I added the mapping in Grant.hbm.xml to try to solve this problem.)</p> <p>If I use line #1 below, NH can't find the Status property on Grant (true). If I use line #2, NH can't find the Grant.PO property on Request (also true). How can I make NH look in the right place? </p> <pre><code> public IList&lt;Request&gt; GetAllActionRequired(string userName) { ISession session = GetSession(); return session .CreateCriteria(typeof (Request)) //.CreateCriteria("Grant") #1 //.SetFetchMode("Grant", FetchMode.Eager) #2a //.SetFetchMode("Grant", FetchMode.Join) #2b .Add(Restrictions.Disjunction() .Add(Restrictions.Conjunction() .Add(Restrictions.Eq("Status", "Draft")) .Add(Restrictions.Eq("Requestor", userName))) .Add(Restrictions.Conjunction() .Add(Restrictions.Eq("Status", "Submitted")) .Add(Restrictions.Eq("Grant.PO", userName))) ...) .List&lt;Request&gt;(); } </code></pre> <p>The query works if I comment out the conjunctions that look in the Grant table, so I'm just not getting the join I want.</p> <p>EDIT, this worked, THANKS!!!</p> <pre><code>return session .CreateCriteria(typeof (Request), "r") .CreateCriteria("Grant", "g") .Add(Restrictions.Disjunction() .Add(Restrictions.Conjunction() .Add(Restrictions.Eq("r.Status", "Draft")) .Add(Restrictions.Eq("r.Requestor", userName))) .Add(Restrictions.Conjunction() .Add(Restrictions.Eq("r.Status", "Submitted")) .Add(Restrictions.Eq("g.PO", userName))) ...) .List&lt;Request&gt;(); </code></pre>
 

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