pelton wrote:
Okay, again my solution is using IQuery objects. If this works for you, then use it:
Okay, I am starting to fall in love with Query By Example (QBE) so I wanted to make this work too, since I use effective dated tables a lot in my business applications.
I have it working!!! But there is a downside. The SQLCriterion is passed on to the database, so it isn't as clean as using HQL that works on the Objects themsevles. This means that the SQL string needs to match your database tables, not your object properties. (If yours happen to match, then no big deal, but my database tables are a little different so I ran into exceptions) Also be sure to use the name of the actual database table rather than the name of the object's class.
Okay here is my solution for your example:
Code:
ICriteria c = Session.CreateCriteria(SearchObject.GetType());
string SQL = "{alias}.date = (select max(effdt.date from {YOUR TABLE NAME} effdt where effdt.Item = {alias}.Item)";
NHibernate.SqlCommand.SqlString sqlObject = new NHibernate.SqlCommand.SqlString(SQL);
object[] emptyObject = new object[] { };
NHibernate.Type.IType[] emptyIType = new NHibernate.Type.IType[] { };
SQLCriterion e = new SQLCriterion(sqlObject, emptyObject, emptyIType);
c.Add(e);
c.List();
Lookout: I had to re-type the code into this posting, so there could be typos!
--Brian