title: linq (to nhibernate) where clause on dynamic property in sql
body: <p>My entity has a property which is derived from other properties</p>
  
  <pre><code>public class MyClass
  {
      public DateTime Deadline { get; set; }
      public Severity Severity 
      {
          return (DateTime.Now - Deadline &lt; new TimeSpan(5, 0, 0, 0)) ? Severity.High : Severity.Low;
      }
  }
  </code></pre>
  
  <p>is there a way I can modify the following</p>
  
  <pre><code>return repository.Query().Where(myClass =&gt; myClass.Severity == High);
  </code></pre>
  
  <p>so that the where clause evaluates in sql rather than in code?</p>
  
  <p>I tried to do something like this, but to no avail</p>
  
  <pre><code>public class MyClass
  {
      public DateTime Deadline { get; set; }
      public Func&lt;MyClass, bool&gt; SeverityFunc = (DateTime.Now - Deadline &lt; new TimeSpan(5, 0, 0, 0)) ? Severity.High : Severity.Low;
      public Severity Severity 
      {
          return SeverityFunc.Invoke(this);
      }
  }
  
  return repository.Query().Where(myClass =&gt; myClass.SeverityFunc(myclass) == High);
  </code></pre>
  
  <p>I'm guessing because the func cant be evaluated to SQL. Is there some other way to do this without ending up with duplicate calculations for severity</p>
  
  <p>Any help appreciated, ta</p>
  
  <p>Edit: This is a simplified version of what im trying to do, i'm looking for answers that cover the theory of this rather than a specific fix (though still welcome). Im interested in whats possible, and best practices to achieve this sort of thing.</p>
  
  <p>Andrew</p>