title: Error variable 'x' of type 'myClass' referenced from scope '', but it is not defined
body: <p>This code works fine:</p>
  
  <pre><code>ICriteria criteria = GetSession().CreateCriteria&lt;MyClass&gt;();
  criteria.Add(Restrictions.Where&lt;MyClass&gt;(x =&gt; x.Field1 &gt;= myVariable));
  </code></pre>
  
  <p>But the following code does not work:</p>
  
  <pre><code>criteria.Add(Restrictions        
          .Where&lt;MyClass&gt;(x =&gt;          
          (x.Field1 +
          x.Field2 +
          x.Field3 +
          x.Field4) &gt;= myVariable));
  </code></pre>
  
  <p>The above code get this error in execution:</p>
  
  <blockquote>
    <p>Variable 'x' of type 'myClass' referenced from scope '', but it is not
    defined</p>
  </blockquote>
  
  <p>Help please (sorry for my bad English).</p>
  
  <p>Sara</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>My Temporary solution is:</p>
  
  <pre><code>var result = criteria.List&lt;MyClass&gt;();    
  result.Where(x =&gt; (x.Field1 + x.Field2 + x.Field3 + x.Field4 &gt;= myVariable));
  </code></pre>
  
  <p>and this work. I would prefer put the Where clause before selection...</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>The final solution is (as suggested from @mhoff):</p>
  
  <pre><code>var result = criteria.List&lt;MyClass&gt;();    
  result.Where(x =&gt; this.GetSum(x) &gt;= myVariable);
  
  ... do something ...
  
  ... ToList()
  
  
  private int GetSum(MyClass x) {
   return (x.Field1 + x.Field2 + x.Field3 + x.Field4);
  }
  </code></pre>