SQL Query in NHibernate diction

Posted by Jan-Frederik Carl on Stack Overflow See other posts from Stack Overflow or by Jan-Frederik Carl
Published on 2010-05-27T13:58:20Z Indexed on 2010/05/27 14:01 UTC
Read the original article Hit count: 230

Filed under:
|
|

I have a SQL Query which works in SQL Management Studio:

Select Id From table t Where t.Date= (Select Max(Date) From ( Select * From table where ReferenceId = xy) u)

Reason is, from all entries with a certain foreign key, I want to receive the one with the highest date.

I tried to reform this Query for use in NHibernate, and I got

IQuery query = session.CreateQuery(String.Format(
            @"Select t.Id  
            From table t
            Where t.Date =
                (Select Max(Date)
                From (Select * 
                      From table t where t.ReferenceItem.Id = " + item.ReferenceItem.Id + ")u)"));

I get the error message: "In expected"

How do I have to form the NHibernate query? What does the "In" mean?

© Stack Overflow or respective owner

Related posts about sql

Related posts about nhibernate