I Use NHibernate criteria and it returns objects with same ids how I can create somethig like "group by" there?
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)
));
}
Because your code is not reproduceable I'm just guessing that you might need to add a transformation at the end.
Try .SetResultTransformer(new DistinctRootEntityResultTransformer());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.