CodeGo.net>如何创建一个子查询投影,给它一个别名,并使用Criteria API在NHibernate中按别名排序
作者:互联网
forum.hibernate.org/viewtopic.php?p=2378849
其中一位张贴者给出了以下答案:
You need to create a Projection (…), give it an alias and you can then sort by the alias.
No time to post the details but I’m pretty sure that would work.
有人可以使用Criteria API提供一个简单的示例,该查询使用Projection进行子查询,然后将该子查询用作别名,然后按该别名进行排序吗?
干杯!
解决方法:
您可以根据需要添加更多的DetachedCriteria.
这是我的样本:
DetachedCriteria sum = DetachedCriteria.For(typeof(MasterAsset), "asset2")
.SetProjection(Projections.Sum("PhysicCondition"));
DetachedCriteria count = DetachedCriteria.For(typeof(MasterAsset), "asset3")
.SetProjection(Projections.Count("PhysicCondition"));
Session.CreateCriteria(typeof(MasterAsset), "asset1")
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("IDMasterAsset"), "IDAsset"))
.Add(Subqueries.PropertyLt("PhysicCondition", sum))
.Add(Subqueries.PropertyLe("PhysicCondition", count))
.AddOrder(Order.Asc("IDAsset"))
.List();
希望能有所帮助.
标签:criteria-api,nhibernate,c,nhibernate-projections 来源: https://codeday.me/bug/20191105/1995865.html