title: FluentNhibernate: Query to retrieve distinct values
body: <p>Using FluentNhibernate 1.3.0.0, NHibernate 3.3.1.4000 on a DB2 LUW 9.7 database.</p>
  
  <p>I want to get some distinct data from only one table / entity. In SQL, it´s easy:</p>
  
  <pre><code>select distinct Corporation, CalculationDate, ValuationRule
  from MySchema.MyTable
  where State == 0
  </code></pre>
  
  <p>Now, i´m trying to get those data using Linq, but it won´t work...</p>
  
  <p>First try using select:</p>
  
  <pre><code>var result = Session.Query&lt;MyEntity&gt;()
          .Where( x =&gt; x.State == State.Pending)
          .Select(
             x =&gt;
                new
                {
                   Corporation = x.Corporation,
                   CalculationDate = x.CalculationDate,
                   ValuationRule = x.ValuationRule,
                }).Distinct().ToList();
  </code></pre>
  
  <p>Resulting exception: Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor.</p>
  
  <p>Second try, using Groupby and only getting the keys:</p>
  
  <pre><code>var result = Session.Query&lt;MyEntity&gt;()
          .Where( x =&gt; x.State == State.Pending)
          .GroupBy(
             x =&gt;
                new
                {
                   Corporation = x.Corporation,
                   CalculationDate = x.CalculationDate,
                   ValuationRule = x.ValuationRule,
                }).Select( x =&gt; x.Key).ToList();
  </code></pre>
  
  <p>Resulting Exception: "Could not execute Query". Complaining about another field "Model" missing in the group by clause that is stated in the select term. This is totally confusing me, as the specified field exists in the table but i dont want to use that field in that use case...</p>
  
  <p>What is it i am missing?</p>