title: Where clause in NHibernate
body: <p>How do I express this in NHibernate?</p>
  
  <pre><code>DECLARE @EntityId INT = 800;
  
  SELECT *
  FROM UserAlert
  WHERE UserAlertId =  
                    (
                     SELECT MAX(UserAlertId)
                     FROM UserAlert
                     WHERE EntityId = @EntityId
                    )
  </code></pre>
  
  <p>This is what I'm trying to do.    </p>
  
  <pre><code>var senderUA = session.CreateCriteria&lt;UserAlert&gt;()
                        .Add(Restrictions.Eq("EntityId", id))
                        .SetProjection( Projections.Max("Id") )
                        . UniqueResult();
  </code></pre>
  
  <p>And I keep getting an error that can convert object to UserAlert type, i.e. it's not even compiling.</p>
  
  <p>Thanks for helping</p>