title: NHibernate linq - Use lambda expression in place of formula attribute on mapping
body: <p>NHibernate has an attribute on the property element in the mapping config named "formula" that allows the injections of sql to "calculate" a property. The issue I have is the formula using sql syntax directly. Is there a way to have nhibernate.linq to use a lambda expression instead of using the formula property. </p>
  
  <p>I have the following:</p>
  
  <pre><code>public class Invoice
  {
      public virtual int Id { get; protected set; }
      public virtual decimal Amount { get; set; }
      public virtual decimal Paid { get; set; }
      public virtual decimal Balance
      {
          get { return BalanceExpression.Expression.Compile().Invoke(this); }
      }
  }
  
  public class BalanceExpression
  {
      public static Expression&lt;Func&lt;Invoice, decimal&gt;&gt; Expression
      {
          get { return i =&gt; i.Amount - i.Paid; }
      }
  }
  
  &lt;class name="Invoice"&gt; 
    &lt;id name="Id"&gt; 
      &lt;generator class="hilo"/&gt; 
    &lt;/id&gt; 
    &lt;property name="Amount"/&gt; 
    &lt;property name="Paid"/&gt; 
    &lt;property name="Balance" formula="Amount - Paid" access="readonly"/&gt; 
  &lt;/class&gt;
  </code></pre>
  
  <p>I want nhibernate to use the balanceexpression.expression instead of having to put sql syntax in the formula attribute so I can remove the formula attribute from my mapping config and write queries as follows:</p>
  
  <p>from i in session.linq()
  where i.balance > 0
  select i;</p>
  
  <p>How do I inject the balanceexpression.expression into the linq query?</p>