public IEnumerable <User> GetUsersAssignedToRank(params UserRank[] userRanks) { using (var session = _sessionProvider.CreateSession()) { return(session.QueryOver <User>().Where(u => RestrictionExtensions.IsIn((object)u.UserRank, (ICollection)userRanks)).List <User>()); } }
static ExpressionProcessor() { _simpleExpressionCreators = new Dictionary <ExpressionType, Func <string, object, ICriterion> >(); _simpleExpressionCreators[ExpressionType.Equal] = Eq; _simpleExpressionCreators[ExpressionType.NotEqual] = Ne; _simpleExpressionCreators[ExpressionType.GreaterThan] = Gt; _simpleExpressionCreators[ExpressionType.GreaterThanOrEqual] = Ge; _simpleExpressionCreators[ExpressionType.LessThan] = Lt; _simpleExpressionCreators[ExpressionType.LessThanOrEqual] = Le; _propertyExpressionCreators = new Dictionary <ExpressionType, Func <string, string, ICriterion> >(); _propertyExpressionCreators[ExpressionType.Equal] = Restrictions.EqProperty; _propertyExpressionCreators[ExpressionType.NotEqual] = Restrictions.NotEqProperty; _propertyExpressionCreators[ExpressionType.GreaterThan] = Restrictions.GtProperty; _propertyExpressionCreators[ExpressionType.GreaterThanOrEqual] = Restrictions.GeProperty; _propertyExpressionCreators[ExpressionType.LessThan] = Restrictions.LtProperty; _propertyExpressionCreators[ExpressionType.LessThanOrEqual] = Restrictions.LeProperty; _subqueryExpressionCreatorTypes = new Dictionary <LambdaSubqueryType, IDictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> > >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.All] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.Equal] = Subqueries.PropertyEq; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.NotEqual] = Subqueries.PropertyNe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.GreaterThan] = Subqueries.PropertyGt; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.LessThan] = Subqueries.PropertyLt; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.Equal] = Subqueries.PropertyEqAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.GreaterThan] = Subqueries.PropertyGtAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGeAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.LessThan] = Subqueries.PropertyLtAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLeAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.GreaterThan] = Subqueries.PropertyGtSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGeSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThan] = Subqueries.PropertyLtSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLeSome; _customMethodCallProcessors = new Dictionary <string, Func <MethodCallExpression, ICriterion> >(); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", ""), RestrictionExtensions.ProcessIsLike); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null), RestrictionExtensions.ProcessIsLikeMatchMode); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null, null), RestrictionExtensions.ProcessIsLikeMatchModeEscapeChar); RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", ""), RestrictionExtensions.ProcessIsInsensitiveLike); RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", "", null), RestrictionExtensions.ProcessIsInsensitiveLikeMatchMode); RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, new object[0]), RestrictionExtensions.ProcessIsInArray); RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, new List <object>()), RestrictionExtensions.ProcessIsInCollection); RegisterCustomMethodCall(() => RestrictionExtensions.IsBetween(null, null).And(null), RestrictionExtensions.ProcessIsBetween); }
static ExpressionProcessor() { _simpleExpressionCreators = new Dictionary <ExpressionType, Func <ProjectionInfo, object, ICriterion> >(); _simpleExpressionCreators[ExpressionType.Equal] = Eq; _simpleExpressionCreators[ExpressionType.NotEqual] = Ne; _simpleExpressionCreators[ExpressionType.GreaterThan] = Gt; _simpleExpressionCreators[ExpressionType.GreaterThanOrEqual] = Ge; _simpleExpressionCreators[ExpressionType.LessThan] = Lt; _simpleExpressionCreators[ExpressionType.LessThanOrEqual] = Le; _propertyExpressionCreators = new Dictionary <ExpressionType, Func <ProjectionInfo, ProjectionInfo, ICriterion> >(); _propertyExpressionCreators[ExpressionType.Equal] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.EqProperty, Restrictions.EqProperty, Restrictions.EqProperty, Restrictions.EqProperty); _propertyExpressionCreators[ExpressionType.NotEqual] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.NotEqProperty, Restrictions.NotEqProperty, Restrictions.NotEqProperty, Restrictions.NotEqProperty); _propertyExpressionCreators[ExpressionType.GreaterThan] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.GtProperty, Restrictions.GtProperty, Restrictions.GtProperty, Restrictions.GtProperty); _propertyExpressionCreators[ExpressionType.GreaterThanOrEqual] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.GeProperty, Restrictions.GeProperty, Restrictions.GeProperty, Restrictions.GeProperty); _propertyExpressionCreators[ExpressionType.LessThan] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.LtProperty, Restrictions.LtProperty, Restrictions.LtProperty, Restrictions.LtProperty); _propertyExpressionCreators[ExpressionType.LessThanOrEqual] = (lhs, rhs) => lhs.CreateCriterion(rhs, Restrictions.LeProperty, Restrictions.LeProperty, Restrictions.LeProperty, Restrictions.LeProperty); _subqueryExpressionCreatorTypes = new Dictionary <LambdaSubqueryType, IDictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> > >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.All] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some] = new Dictionary <ExpressionType, Func <string, DetachedCriteria, AbstractCriterion> >(); _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.Equal] = Subqueries.PropertyEq; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.NotEqual] = Subqueries.PropertyNe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.GreaterThan] = Subqueries.PropertyGt; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.LessThan] = Subqueries.PropertyLt; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Exact][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLe; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.Equal] = Subqueries.PropertyEqAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.GreaterThan] = Subqueries.PropertyGtAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGeAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.LessThan] = Subqueries.PropertyLtAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.All][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLeAll; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.GreaterThan] = Subqueries.PropertyGtSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGeSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThan] = Subqueries.PropertyLtSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLeSome; _customMethodCallProcessors = new Dictionary <string, Func <MethodCallExpression, ICriterion> >(); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", ""), RestrictionExtensions.ProcessIsLike); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null), RestrictionExtensions.ProcessIsLikeMatchMode); RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null, null), RestrictionExtensions.ProcessIsLikeMatchModeEscapeChar); RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", ""), RestrictionExtensions.ProcessIsInsensitiveLike); RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", "", null), RestrictionExtensions.ProcessIsInsensitiveLikeMatchMode); RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, Array.Empty <object>()), RestrictionExtensions.ProcessIsInArray); RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, new List <object>()), RestrictionExtensions.ProcessIsInCollection); RegisterCustomMethodCall(() => RestrictionExtensions.IsBetween(null, null).And(null), RestrictionExtensions.ProcessIsBetween); _customProjectionProcessors = new Dictionary <string, Func <Expression, IProjection> >(); RegisterCustomProjection(() => default(DateTime).Year, e => ProjectionsExtensions.ProcessYear(e.Expression)); RegisterCustomProjection(() => default(DateTime).Day, e => ProjectionsExtensions.ProcessDay(e.Expression)); RegisterCustomProjection(() => default(DateTime).Month, e => ProjectionsExtensions.ProcessMonth(e.Expression)); RegisterCustomProjection(() => default(DateTime).Hour, e => ProjectionsExtensions.ProcessHour(e.Expression)); RegisterCustomProjection(() => default(DateTime).Minute, e => ProjectionsExtensions.ProcessMinute(e.Expression)); RegisterCustomProjection(() => default(DateTime).Second, e => ProjectionsExtensions.ProcessSecond(e.Expression)); RegisterCustomProjection(() => default(DateTime).Date, e => ProjectionsExtensions.ProcessDate(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Year, e => ProjectionsExtensions.ProcessYear(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Day, e => ProjectionsExtensions.ProcessDay(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Month, e => ProjectionsExtensions.ProcessMonth(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Hour, e => ProjectionsExtensions.ProcessHour(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Minute, e => ProjectionsExtensions.ProcessMinute(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Second, e => ProjectionsExtensions.ProcessSecond(e.Expression)); RegisterCustomProjection(() => default(DateTimeOffset).Date, e => ProjectionsExtensions.ProcessDate(e.Expression)); RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(long)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Lower(string.Empty), ProjectionsExtensions.ProcessLower); RegisterCustomProjection(() => ProjectionsExtensions.Upper(string.Empty), ProjectionsExtensions.ProcessUpper); RegisterCustomProjection(() => ProjectionsExtensions.TrimStr(string.Empty), ProjectionsExtensions.ProcessTrimStr); RegisterCustomProjection(() => ProjectionsExtensions.StrLength(string.Empty), ProjectionsExtensions.ProcessStrLength); RegisterCustomProjection(() => ProjectionsExtensions.BitLength(string.Empty), ProjectionsExtensions.ProcessBitLength); RegisterCustomProjection(() => ProjectionsExtensions.Substr(string.Empty, 0, 0), ProjectionsExtensions.ProcessSubstr); RegisterCustomProjection(() => ProjectionsExtensions.CharIndex(string.Empty, string.Empty, 0), ProjectionsExtensions.ProcessCharIndex); RegisterCustomProjection(() => ProjectionsExtensions.Coalesce <DBNull>(null, null), ProjectionsExtensions.ProcessCoalesce); RegisterCustomProjection(() => ProjectionsExtensions.Coalesce <int>(null, 0), ProjectionsExtensions.ProcessCoalesce); RegisterCustomProjection(() => Projections.Concat(null), Projections.ProcessConcat); RegisterCustomProjection(() => ProjectionsExtensions.Mod(0, 0), ProjectionsExtensions.ProcessMod); RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(int)), ProjectionsExtensions.ProcessIntAbs); RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(double)), ProjectionsExtensions.ProcessDoubleAbs); RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(Int64)), ProjectionsExtensions.ProcessInt64Abs); RegisterCustomProjection(() => Math.Round(default(double)), ProjectionsExtensions.ProcessRound); RegisterCustomProjection(() => Math.Round(default(decimal)), ProjectionsExtensions.ProcessRound); RegisterCustomProjection(() => Math.Round(default(double), default(int)), ProjectionsExtensions.ProcessRound); RegisterCustomProjection(() => Math.Round(default(decimal), default(int)), ProjectionsExtensions.ProcessRound); RegisterCustomProjection(() => ProjectionsExtensions.AsEntity(default(object)), ProjectionsExtensions.ProcessAsEntity); }
private IQueryOver <VodovozOrder> GetOrdersQuery(IUnitOfWork uow) { OrderForRouteListJournalNode resultAlias = null; VodovozOrder orderAlias = null; Nomenclature nomenclatureAlias = null; OrderItem orderItemAlias = null; Counterparty counterpartyAlias = null; DeliveryPoint deliveryPointAlias = null; DeliverySchedule deliveryScheduleAlias = null; Employee authorAlias = null; Employee lastEditorAlias = null; District districtAlias = null; Nomenclature sanitizationNomenclature = new NomenclatureParametersProvider(new ParametersProvider()).GetSanitisationNomenclature(uow); var query = uow.Session.QueryOver <VodovozOrder>(() => orderAlias); if (FilterViewModel.ViewTypes != ViewTypes.Order && FilterViewModel.ViewTypes != ViewTypes.All) { query.Where(o => o.Id == -1); } if (FilterViewModel.RestrictStatus != null) { query.Where(o => o.OrderStatus == FilterViewModel.RestrictStatus); } if (FilterViewModel.RestrictPaymentType != null) { query.Where(o => o.PaymentType == FilterViewModel.RestrictPaymentType); } if (FilterViewModel.HideStatuses != null) { query.WhereRestrictionOn(o => o.OrderStatus).Not.IsIn(FilterViewModel.HideStatuses); } if (FilterViewModel.RestrictOnlySelfDelivery != null) { query.Where(o => o.SelfDelivery == FilterViewModel.RestrictOnlySelfDelivery); } if (FilterViewModel.RestrictWithoutSelfDelivery != null) { query.Where(o => o.SelfDelivery != FilterViewModel.RestrictWithoutSelfDelivery); } if (FilterViewModel.RestrictCounterparty != null) { query.Where(o => o.Client == FilterViewModel.RestrictCounterparty); } if (FilterViewModel.DeliveryPoint != null) { query.Where(o => o.DeliveryPoint == FilterViewModel.DeliveryPoint); } if (FilterViewModel.RestrictStartDate != null) { query.Where(o => o.DeliveryDate >= FilterViewModel.RestrictStartDate); } if (FilterViewModel.RestrictEndDate != null) { query.Where(o => o.DeliveryDate <= FilterViewModel.RestrictEndDate.Value.AddDays(1).AddTicks(-1)); } if (FilterViewModel.RestrictLessThreeHours == true) { query.Where(Restrictions .GtProperty(Projections.SqlFunction( new SQLFunctionTemplate(NHibernateUtil.Time, "ADDTIME(?1, ?2)"), NHibernateUtil.Time, Projections.Property(() => deliveryScheduleAlias.From), Projections.Constant("3:0:0")), Projections.Property(() => deliveryScheduleAlias.To))); } if (FilterViewModel.RestrictHideService != null) { if (FilterViewModel.RestrictHideService.Value) { query.Where(o => o.OrderAddressType != OrderAddressType.Service); } else { query.Where(o => o.OrderAddressType == OrderAddressType.Service); } } if (FilterViewModel.RestrictOnlyService != null) { if (FilterViewModel.RestrictOnlyService.Value) { query.Where(o => o.OrderAddressType == OrderAddressType.Service); } else { query.Where(o => o.OrderAddressType != OrderAddressType.Service); } } if (FilterViewModel.OrderPaymentStatus != null) { query.Where(o => o.OrderPaymentStatus == FilterViewModel.OrderPaymentStatus); } var bottleCountSubquery = QueryOver.Of <OrderItem>(() => orderItemAlias) .Where(() => orderAlias.Id == orderItemAlias.Order.Id) .JoinAlias(() => orderItemAlias.Nomenclature, () => nomenclatureAlias) .Where(() => nomenclatureAlias.Category == NomenclatureCategory.water && nomenclatureAlias.TareVolume == TareVolume.Vol19L) .Select(Projections.Sum(() => orderItemAlias.Count)); var sanitisationCountSubquery = QueryOver.Of <OrderItem>(() => orderItemAlias) .Where(() => orderAlias.Id == orderItemAlias.Order.Id) .Where(() => orderItemAlias.Nomenclature.Id == sanitizationNomenclature.Id) .Select(Projections.Sum(() => orderItemAlias.Count)); var orderSumSubquery = QueryOver.Of <OrderItem>(() => orderItemAlias) .Where(() => orderItemAlias.Order.Id == orderAlias.Id) .Select( Projections.Sum( Projections.SqlFunction( new SQLFunctionTemplate(NHibernateUtil.Decimal, "?1 * ?2 - IF(?3 IS NULL OR ?3 = 0, IFNULL(?4, 0), ?3)"), NHibernateUtil.Decimal, Projections.Property <OrderItem>(x => x.Count), Projections.Property <OrderItem>(x => x.Price), Projections.Property <OrderItem>(x => x.DiscountMoney), Projections.Property <OrderItem>(x => x.OriginalDiscountMoney) ) ) ); query.Left.JoinAlias(o => o.DeliveryPoint, () => deliveryPointAlias) .Left.JoinAlias(o => o.DeliverySchedule, () => deliveryScheduleAlias) .Left.JoinAlias(o => o.Client, () => counterpartyAlias) .Left.JoinAlias(o => o.Author, () => authorAlias) .Left.JoinAlias(o => o.LastEditor, () => lastEditorAlias) .Left.JoinAlias(() => deliveryPointAlias.District, () => districtAlias); query.Where(GetSearchCriterion( () => orderAlias.Id, () => counterpartyAlias.Name, () => deliveryPointAlias.CompiledAddress, () => authorAlias.LastName, () => orderAlias.DriverCallId, () => orderAlias.OnlineOrder, () => orderAlias.EShopOrder, () => orderAlias.OrderPaymentStatus )); if (FilterViewModel.IncludeDistrictsIds != null && FilterViewModel.IncludeDistrictsIds.Any()) { query = query.Where(() => deliveryPointAlias.District.Id.IsIn(FilterViewModel.IncludeDistrictsIds)); } // Для того чтобы уже добавленные в МЛ заказы больше не появлялись if (FilterViewModel.ExceptIds != null && FilterViewModel.ExceptIds.Any()) { query.Where(o => !RestrictionExtensions.IsIn(o.Id, FilterViewModel.ExceptIds)); } var resultQuery = query .SelectList(list => list .Select(() => orderAlias.Id).WithAlias(() => resultAlias.Id) .Select(() => orderAlias.SelfDelivery).WithAlias(() => resultAlias.IsSelfDelivery) .Select(() => deliveryScheduleAlias.Name).WithAlias(() => resultAlias.DeliveryTime) .Select(() => orderAlias.OrderStatus).WithAlias(() => resultAlias.StatusEnum) .Select(() => orderAlias.Address1c).WithAlias(() => resultAlias.Address1c) .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorLastName) .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName) .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic) .Select(() => counterpartyAlias.Name).WithAlias(() => resultAlias.Counterparty) .Select(() => districtAlias.DistrictName).WithAlias(() => resultAlias.DistrictName) .Select(() => deliveryPointAlias.CompiledAddress).WithAlias(() => resultAlias.CompilledAddress) .Select(() => deliveryPointAlias.City).WithAlias(() => resultAlias.City) .Select(() => deliveryPointAlias.Street).WithAlias(() => resultAlias.Street) .Select(() => deliveryPointAlias.Building).WithAlias(() => resultAlias.Building) .SelectSubQuery(orderSumSubquery).WithAlias(() => resultAlias.Sum) .SelectSubQuery(bottleCountSubquery).WithAlias(() => resultAlias.BottleAmount) .SelectSubQuery(sanitisationCountSubquery).WithAlias(() => resultAlias.SanitisationAmount) ) .OrderBy(x => x.CreateDate).Desc .TransformUsing(Transformers.AliasToBean <OrderForRouteListJournalNode <VodovozOrder> >()); return(resultQuery); }