NHibernate,子查询选择最大值,正确的查询形成,但没有执行

时间:2010-06-28 12:54:52

标签: nhibernate

IList lFolioHistory;
ISession session = NHibernateHelper.GetCurrentSession();

var detq = NHibernate.Criterion.DetachedCriteria.For<FolioHistory>("e2");
detq.SetProjection(Projections.Alias(Projections.Max("Foliohistdate"), "maxFoliohistdate"));

detq.Add(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();

正确的查询形成如下,但不执行。

  

选择this_.foliohist_id如foliohist1_27_0_,this_.member_id如member2_27_0_,this_.foliohist_txnamt如foliohist3_27_0_,this_.foliohist_date如foliohist4_27_0_,this_.foliohist_balance如foliohist5_27_0_,this_.foliohist_remarks如foliohist6_27_0_,this_.foliohist_crby如foliohist7_27_0_ FROM hbms_foliohistory THIS_ WHERE THIS_ .member_id =?p0和this_.foliohist_date =(SELECT max(this_0_.foliohist_date)as y0_ FROM hbms_foliohistory this_0_ WHERE this_0_.member_id = this_.member_id)

1 个答案:

答案 0 :(得分:0)

查询未执行,并且正在抛出错误。最后发现它是一个日期错误。解决了它。很抱歉打扰你们。