[NUnit.Framework.Test] public void SubFieldQuery() { var session = Z.Core.NHibernateCore.NHibernateHelper.GetCurrentSession(); var subCrit = NHibernate.Criterion.DetachedCriteria.For<Model.Sys.Manager>("M"); subCrit.SetProjection(NHibernate.Criterion.Projections.Property("Name")); subCrit.SetMaxResults(1); //subCrit.Add(NHibernate.Criterion.Expression.EqProperty("M.ParentCompany.Guid", "C.Guid")); //that is right //but I want user Expression.Sql subCrit.Add(NHibernate.Criterion.Expression.Sql("Convert(nvarchar(50),{alias}.CompanyGuid) = this_.Guid")); //The result is correct, but "this_.Guid" => how to use "{alias.Criterion}.Guid" or "{alias.Parent}.Guid" //Thanks var crit = session.CreateCriteria<Model.Sys.Company>("C"); crit.SetProjection(NHibernate.Criterion.Projections.ProjectionList() .Add(NHibernate.Criterion.Projections.SubQuery(subCrit))); var list = crit.List(); Console.Write(list.Count); }
|