IList lFolioHistory; ISession session = NHibernateHelper.GetCurrentSession();
var detq = NHibernate.Criterion.DetachedCriteria.For("e2");
detq.SetProjection(NHibernate.Criterion.Projections.Alias(NHibernate.Criterion.Projections.Max("Foliohistdate"), "maxFoliohistdate"));
detq.Add(NHibernate.Criterion.Restrictions.EqProperty("e2.Memberid", "e.Memberid"));
ICriteria sc = session.CreateCriteria(typeof(FolioHistory), "e");
sc.Add(NHibernate.Criterion.Restrictions.Eq("e.Memberid", iMemberId));
sc.Add(NHibernate.Criterion.Subqueries.PropertyEq("Foliohistdate", detq));
lFolioHistory = sc.List();
right query is formed as below, but doesn't get executed.
SELECT this_.foliohist_id as foliohist1_27_0_, this_.member_id as member2_27_0_, this_.foliohist_txnamt as foliohist3_27_0_, this_.foliohist_date as foliohist4_27_0_, this_.foliohist_balance as foliohist5_27_0_, this_.foliohist_remarks as foliohist6_27_0_, this_.foliohist_crby as foliohist7_27_0_ FROM hbms_foliohistory this_ WHERE this_.member_id = ?p0 and this_.foliohist_date = (SELECT max(this_0_.foliohist_date) as y0_ FROM hbms_foliohistory this_0_ WHERE this_0_.member_id = this_.member_id)