title: In NHibernate, using a Disjunction gives double results
body: <p>I'm trying to make a select with DetachedCriteria, I want to add several conditions seperated by OR at runtime.</p>
  
  <p>If I use:</p>
  
  <pre><code>Restrictions.Or( cond1, Restrictions.Or(cond2, Restrictions.Or(cond3, cond4)) )
  </code></pre>
  
  <p>I get the result I want.</p>
  
  <p>But if I use a Disjunction like so:</p>
  
  <pre><code>var disjunction = Restrictions.Disjunction();
  disjunction.Add(cond1);
  disjunction.Add(cond2);
  disjunction.Add(cond3);
  disjunction.Add(cond4);
  </code></pre>
  
  <p>And I have entities that cond1 and cond2 are true for them, at the results I get them twice (the same exact entity is returned twice in the list result).</p>
  
  <p>I do not wish to use QueryOver because I'm trying to accomplish something that is hard to do with QueryOver (the end result of what I'm trying to do is to get an sql query from a json of filters).</p>
  
  <p>What's causing the disjunction to return doubles? Is there a way to add a DISTINCT at the end? Am I doing it wrong and I shouldn't use disjunction for different conditions on the same table?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>For the DISTINCT part:</p>
  
  <pre><code>criteria.SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer());
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Projections.Distinct(Projections.Id())
  </code></pre>
  
  <p>The real solution is as stated by <em>Radim Köhler</em> - The correct use of a sub query.</p>