我使用NHibernate标准并返回具有相同ID的对象我如何创建像“group by”那样的东西?
public List<ProducerRelation> GetByDateRangeAndUser(DateTime from, DateTime till, string user,
ICollection exeptedIds)
{
var criteria = NHibernateSession.CreateCriteria(typeof(ProducerRelation));
AddCriterionByRouteUnitDate(criteria, from, till, exeptedIds);
criteria.Add(Restrictions.Eq(
String.Format("{0}.{1}", ProducerRelation.Properties.Order,
BackOffice.Core.Domains.Order.Properties.CreatedBy), user));
return criteria.List<ProducerRelation>() as List<ProducerRelation>;
}
private void AddCriterionByRouteUnitDate(ICriteria crit, DateTime from, DateTime till,
ICollection exeptedIds)
{
crit.CreateAlias(ProducerRelation.Properties.Order, ProducerRelation.Properties.Order);
crit.CreateAlias(String.Format("{0}.{1}",
ProducerRelation.Properties.Order,
bModel.Order.Properties.RouteUnits), ProducerRelation.Properties.RouteUnit)
.Add(Restrictions.Between(
String.Format("{0}.{1}", ProducerRelation.Properties.RouteUnit, RouteUnit.Properties.DtStart),
from, till))
.Add(Restrictions.Not(
Restrictions.In(ProducerRelation.Properties.Id, exeptedIds)
));
}
答案 0 :(得分:0)
因为你的代码不可复制,所以我猜你可能需要在最后添加一个转换。
尝试.SetResultTransformer(new DistinctRootEntityResultTransformer());