public DateTime?GetMinDateJournal() { ICriteria criteria = Session.CreateCriteria(typeof(TJournal)) .SetProjection(Projections.Min("JournalDate")); object obj = criteria.UniqueResult(); if (obj != null) { return(Convert.ToDateTime(obj)); } else { return(null); } DateTime dt = criteria.FutureValue <DateTime>().Value; return(dt); try { } catch (Exception) { return(null); } }
public DateTime?GetLastDateClosing() { ICriteria criteria = Session.CreateCriteria(typeof(TRecPeriod)) .SetProjection(Projections.Max("PeriodTo")); object obj = criteria.UniqueResult(); if (obj != null) { return(Convert.ToDateTime(obj)); } else { return(null); } DateTime dt = criteria.FutureValue <DateTime>().Value; return(dt); try { } catch (Exception) { return(null); } }
/// <summary> /// Versuch über ein Detached Criteria die Where-Klauseln zu verarbeiten, damit es mit dem Order nicht zu /// komplikationen kommt. /// </summary> protected virtual IPage <T> Find(IPageable pageable, Action <DetachedCriteria> criteriaBuilder, Action <ICriteria> ordersBuilder = null) { Require.NotNull(pageable, "pageable"); Require.NotNull(criteriaBuilder, "criteriaBuilder"); HibernateDelegate <IPage <T> > finder = delegate(ISession session) { DetachedCriteria whereCriteria = DetachedCriteria.For(typeof(T)); criteriaBuilder(whereCriteria); whereCriteria.SetProjection(Projections.Property("Id")); ICriteria elementsCriteria = session.CreateCriteria(typeof(T)); elementsCriteria.Add(Subqueries.PropertyIn("Id", whereCriteria)); if (ordersBuilder != null) { ordersBuilder(elementsCriteria); } ApplyPaging(pageable, elementsCriteria); ICriteria countCriteria = session.CreateCriteria(typeof(T)); countCriteria.Add(Subqueries.PropertyIn("Id", whereCriteria)); countCriteria.SetProjection(Projections.RowCountInt64()); IFutureValue <long> futureTotalCount = countCriteria.FutureValue <long>(); IEnumerable <T> futureElements = elementsCriteria.Future <T>(); Page <T> page = new Page <T>(futureElements.ToList(), pageable, futureTotalCount.Value); return(page); }; return(HibernateTemplate.Execute(finder)); }
private void CreateCriteriaOrFutures() { _mainCriteria = _session.CreateCriteria <T>().Add(Restrictions.IdEq(_id)).SetTimeout(_timeoutInSeconds); if (_childNodesInfo != null) { bool rootHasList = false; //only one list can be joined with the main query var childCriterias = new List <ICriteria>(); PopulateChildrenCriteria(_childNodesInfo, CriteriaTransformer.Clone(_mainCriteria), _mainCriteria, ref rootHasList, childCriterias); if (childCriterias.Count > 0 || _deferred) { _mainFuture = _mainCriteria.FutureValue <T>(); _childFutures = childCriterias.Select(c => c.Future <T>()).ToList(); } } else if (_deferred) { _mainFuture = _mainCriteria.FutureValue <T>(); } }
/// <summary> /// Creates a value query selection. /// </summary> /// <param name="query"> /// The query. /// </param> /// <typeparam name="TSource"> /// The <see cref="System.Type" /> of the source entity. /// </typeparam> /// <typeparam name="TDestination"> /// The <see cref="System.Type" /> of the result. /// </typeparam> /// <returns> /// An action to retrieve the selected value. /// </returns> public static Func <TDestination> SelectValue <TSource, TDestination>(IQueryableFlowQuery query) where TSource : class { ICriteriaBuilder criteriaBuilder = GetCriteriaBuilder(query); ICriteria criteria = criteriaBuilder.Build <TSource, TDestination>(query); if (query.IsDelayed) { IFutureValue <TDestination> value = criteria.FutureValue <TDestination>(); return(() => value.Value); } return(criteria.UniqueResult <TDestination>); }
static public PagedResult <DTO> ToExPagedResults <DTO, Model>(this IQueryOver <Model, Model> query, PartialRetrievingInfo retrievingInfo, IQueryOver <Model, Model> idQuery, Func <IEnumerable <Model>, DTO[]> mappingMethod = null) where Model : FMGlobalObject { IEnumerable <Model> queryEnumerable = null; int count = 0; query = query.TransformUsing(Transformers.DistinctRootEntity); if (retrievingInfo.PageSize > PartialRetrievingInfo.AllElementsPageSize) { ICriteria countCriteria = CriteriaTransformer.Clone(idQuery.RootCriteria); countCriteria.SetProjection(Projections.CountDistinct("GlobalId")); IFutureValue <int> rowCountQuery = countCriteria.FutureValue <int>(); idQuery = (QueryOver <Model, Model>)idQuery.ApplyPaging(retrievingInfo); var ids = idQuery.Select(Projections.Distinct(Projections.Property("GlobalId"))).Future <Guid>(); count = rowCountQuery.Value; query = query.WhereRestrictionOn(x => x.GlobalId).IsIn(ids.ToList()); queryEnumerable = query.List(); } else { var ids = idQuery.Select(Projections.Distinct(Projections.Property("GlobalId"))).Future <Guid>(); query = query.WhereRestrictionOn(x => x.GlobalId).IsIn(ids.ToList()); queryEnumerable = query.List(); count = queryEnumerable.Count(); } DTO[] list = null; if (mappingMethod == null) { var temp = queryEnumerable.ToList(); list = Mapper.Map <IEnumerable <Model>, DTO[]>(temp); } else { list = mappingMethod(queryEnumerable); } PagedResult <DTO> res = new PagedResult <DTO>(list, count, retrievingInfo.PageIndex); res.RetrievedDateTime = DateTime.UtcNow; Log.WriteInfo("Paged result. AllCount:{0},PageIndex:{1},PageSize:{2}", res.AllItemsCount, res.PageIndex, res.Items.Count); return(res); }
/// <summary> /// Liefert eine Liste mit Entities entsprechend der Pageinformationen /// aus der Menge aller Entitäten. /// </summary> /// <param name="pageable">Beschreibung welche Menge der Entitäten zurückgeliefert werden.</param> /// <returns>Liste mit Entitäten.</returns> public virtual IPage <T> GetAll(IPageable pageable) { Require.NotNull(pageable, "pageable"); HibernateDelegate <IPage <T> > finder = delegate(ISession session) { ICriteria elementsCriteria = session.CreateCriteria(typeof(T)); elementsCriteria.AddOrder(Order.Asc("Id")); ApplyPaging(pageable, elementsCriteria); ICriteria countCriteria = session.CreateCriteria(typeof(T)); countCriteria.SetProjection(Projections.RowCountInt64()); IFutureValue <long> futureTotalCount = countCriteria.FutureValue <long>(); IEnumerable <T> futureElements = elementsCriteria.Future <T>(); Page <T> page = new Page <T>(futureElements.ToList(), pageable, futureTotalCount.Value); return(page); }; return(HibernateTemplate.Execute(finder)); }