private ICriteria GetDatamartCriteria(int top, DetachedCriteria dc, ProjectionList pl, Order order) { ICriteria crit = GetDatamartCriteria(top, dc, order); crit.SetProjection(pl); return(crit); }
/// <summary> /// 所有实体列表 /// </summary> /// <param name="columnNames">列名</param> /// <param name="condition">条件</param> /// <param name="orderBy">排序字段</param> /// <param name="ascending">是否降序</param> /// <returns>返回结果</returns> public IList <TEntity> All(IList <string> columnNames, string condition, string orderBy, bool ascending) { ICriteria criteria = _session.CreateCriteria(typeof(TEntity)); //添加排序字段 if (!string.IsNullOrEmpty(orderBy)) { criteria.AddOrder(new Order(orderBy, ascending)); } //添加列 ProjectionList projectionList = Projections.ProjectionList(); foreach (string col in columnNames) { projectionList.Add(Projections.Property(col), col); } //添加查询条件 if (!string.IsNullOrEmpty(condition)) { criteria.Add(Expression.Sql(condition)); } criteria.SetProjection(projectionList); criteria.SetResultTransformer(Transformers.AliasToBean <TEntity>()); criteria.SetCacheable(true);//设置缓存 return(criteria.List <TEntity>()); }
public ICriteria SetProjection(params IProjection[] projections) { if (projections == null) { throw new ArgumentNullException("projections"); } if (projections.Length == 0) { throw new ArgumentException("projections must contain a least one projection"); } if (projections.Length == 1) { projection = projections[0]; } else { var projectionList = new ProjectionList(); foreach (var childProjection in projections) { projectionList.Add(childProjection); } projection = projectionList; } if (projection != null) { projectionCriteria = this; SetResultTransformer(CriteriaSpecification.Projection); } return(this); }
/// <summary> /// /// </summary> /// <param name="projections"></param> /// <returns></returns> public IEnumerable <T> GetAll(ProjectionList projections) { return(_sessionFactory.GetCurrentSession() .CreateCriteria(typeof(T)) .SetProjection(projections) .List <T>()); }
public IEnumerable <OperatorRanking> GetOperatorsRanking(DateTime desde, DateTime hasta, List <int> choferes) { OperatorRanking or = null; DetachedCriteria dc = GetDatamartDetachedCriteria().FilterBeginBetween(desde, hasta); if (choferes.Count <= SQLParameterLimit) { dc.Add(Restrictions.In(Projections.Property <Datamart>(p => p.Employee.Id), choferes)); } ProjectionList pl = Projections.ProjectionList(); pl.Add(Projections.Sum <Datamart>(dm => dm.Kilometers).WithAlias(() => or.Kilometros)); pl.Add(Projections.Sum <Datamart>(dm => dm.MovementHours).WithAlias(() => or.Hours)); pl.Add(Projections.Group <Datamart>(dm => dm.Employee.Id).WithAlias(() => or.IdOperador)); ICriteria crit = GetDatamartCriteria(0, dc, pl, null, typeof(OperatorRanking)); IList <OperatorRanking> results = crit.List <OperatorRanking>(); var empleadoDAO = new EmpleadoDAO(); foreach (OperatorRanking r in results) { Empleado empleado = empleadoDAO.FindById(r.IdOperador); r.Operador = empleado.Entidad.Apellido; r.Legajo = empleado.Legajo; } IEnumerable <OperatorRanking> result = (choferes.Count > SQLParameterLimit ? results.Where(c => choferes.Contains(c.IdOperador)) : results); return(result); }
/// <summary> /// Removes the specified object from the RelatedObjectList. /// </summary> /// <param name="item">The object to remove from the RelatedObjectList.</param> /// <returns></returns> public bool Remove(TypeProjection item) { if (IsReadOnly) { throw new InvalidOperationException("Cannot remove from a read-only list."); } if (item == null) { throw new ArgumentNullException("Cannot remove a null value on a RelatedObjectList."); } if (!IsOfType(typeof(T), item.GetType())) { throw new InvalidOperationException("This RelatedObjectList only supports removing objects of type " + typeof(T).Name); } foreach (ExpandoObject obj in ProjectionList) { if (AreProjectionsEqual(obj, item.CurrentObject)) { bool success = ProjectionList.Remove(obj); if (success) { Owner.IsDirty = true; } return(success); } } return(false); }
/// <summary> /// Gets mobile maintenance aggregat data for the specified vehicles. /// </summary> /// <param name="desde"></param> /// <param name="hasta"></param> /// <param name="vehiculos"></param> /// <returns></returns> public IEnumerable <MobileMaintenance> GetMobileMaintenanceData(DateTime desde, DateTime hasta, IEnumerable <Coche> vehiculos) { MobileMaintenance mm = null; int[] ids = vehiculos.Select(c => c.Id).ToArray(); DetachedCriteria dc = GetDatamartDetachedCriteria(ids).FilterBeginBetween(desde, hasta); ProjectionList pl = Projections.ProjectionList(); pl.Add(Projections.Sum <Datamart>(dm => dm.MovementHours).WithAlias(() => mm.HsMarcha)); pl.Add(Projections.Sum <Datamart>(dm => dm.Kilometers).WithAlias(() => mm.Kilometros)); pl.Add(Projections.Group <Datamart>(dm => dm.Vehicle.Id).WithAlias(() => mm.IdVehiculo)); ICriteria crit = GetDatamartCriteria(0, dc, pl, null, typeof(MobileMaintenance)); IList <MobileMaintenance> results = crit.List <MobileMaintenance>(); var cocheDAO = new CocheDAO(); foreach (MobileMaintenance r in results) { Coche coche = cocheDAO.FindById(r.IdVehiculo); r.Interno = coche.Interno; r.TipoVehiculo = coche.TipoCoche != null ? coche.TipoCoche.Descripcion : null; r.Patente = coche.Patente; r.Referencia = coche.Referencia; } return(results); }
/// <summary> /// Adds the specified projection list. /// </summary> /// <typeparam name="TTo">The type of to.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="projectionList">The projection list.</param> /// <param name="projection">The projection.</param> /// <param name="alias">The alias.</param> /// <returns>A <see cref="ProjectionList"/></returns> public static ProjectionList Add <TTo, TProperty> ( this ProjectionList projectionList, IProjection projection, Expression <Func <TTo, TProperty> > alias) { return(projectionList.Add(projection, PropertyUtil.ExtractPropertyName(alias))); }
public IDictionary <string, int> getYearlyCompanyMap() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StatisticsManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria criteria = DetachedCriteria.For <Entity_CompanyDetails>(); criteria.Add(Restrictions.Eq("status", Utility.getEnumIndexByValue(Constant.ENUM_COMPANY_STATUS, EnumData.companyStatus.CONFIRMED.ToString()))); criteria.Add(Restrictions.Eq("myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); ProjectionList projectionList = Projections.ProjectionList(); projectionList.Add(Projections.GroupProperty(Projections.Property("myConfigObj.currentBatch"))); projectionList.Add(Projections.Count(Projections.Property("compDetailsId"))); criteria.SetProjection(projectionList); IList list = persistence.findByCriteria(criteria); if (list != null && list.Count > 0) { IDictionary <string, int> resultMap = new Dictionary <string, int>(); foreach (Object[] item in list) { resultMap.Add(item[0].ToString(), Convert.ToInt32(item[1])); } return(resultMap); } else { return(null); } }
public IList getCompanyStatCount() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StatisticsManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria criteria = DetachedCriteria.For <Entity_CompanyDetails>(); criteria.Add(Restrictions.Eq("myConfigObj.currentBatch", Common.loggedUser.myConfigObj.currentBatch)); criteria.Add(Restrictions.Eq("myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); ProjectionList projectionList = Projections.ProjectionList(); projectionList.Add(Projections.Count((Projections.Property("status")))); projectionList.Add(Projections.GroupProperty(Projections.Property("status"))); criteria.SetProjection(projectionList); criteria.AddOrder(Order.Desc(Projections.Property("status"))); IList list = persistence.findByCriteria(criteria); if (list != null && list.Count > 0) { return(list); } else { return(null); } }
private void ProcessSelect(string value) { // the select fields are split by ',' var fields = value.Split(','); _projections = GetProjections(fields); }
public List <HistoricView> GetHistoricPrices(int priceBaseId) { PriceBase pb = ControllerManager.PriceBase.GetById(priceBaseId); if (pb == null) { return(null); } ICriteria crit = GetCriteria(); crit.Add(Expression.Eq("Product", pb.Product)); crit.Add(Expression.Eq("Provider", pb.Provider)); ProjectionList pl = Projections.ProjectionList(); pl.Add(Projections.Distinct(Projections.Property("PriceList"))); pl.Add(Projections.Property("TimeStamp.ModifiedOn")); crit.SetProjection(pl); crit.AddOrder(new Order("TimeStamp.ModifiedOn", true)); IList lst = crit.List(); List <HistoricView> hv = new List <HistoricView>(); foreach (object[] arr in lst) { hv.Add(new HistoricView(StringFormat.MilliTimeStamp((DateTime)arr[1]), Convert.ToDecimal(arr[0]))); } return(hv); }
public virtual void AddProjection(ProjectionList projections) { string propertyName = String.Join(".", _accessor.PropertyNames); var projection = Projections.Property(propertyName).As(_accessor.Name); projections.Add(projection); }
/// <summary> /// Gets aggregate activity for each specified transport company. /// </summary> /// <param name="desde"></param> /// <param name="hasta"></param> /// <param name="ids"></param> /// <returns></returns> public IEnumerable <TransportActivity> GetTransportActivities(DateTime desde, DateTime hasta, List <int> ids) { TransportActivity ta = null; DetachedCriteria dc = GetDatamartDetachedCriteria(ids.ToArray()).FilterBeginBetween(desde, hasta); ProjectionList pl = Projections.ProjectionList(); pl.Add(Projections.Sum <Datamart>(dm => dm.MovementHours).WithAlias(() => ta.HsActivos)); pl.Add(Projections.Sum <Datamart>(dm => dm.StoppedHours).WithAlias(() => ta.HsInactivos)); pl.Add(Projections.Sum <Datamart>(dm => dm.InfractionMinutes).WithAlias(() => ta.HsInfraccion)); pl.Add(Projections.Sum <Datamart>(dm => dm.Infractions).WithAlias(() => ta.Infracciones)); pl.Add(Projections.Sum <Datamart>(dm => dm.Kilometers).WithAlias(() => ta.Recorrido)); pl.Add(Projections.Max <Datamart>(dm => dm.MaxSpeed).WithAlias(() => ta.VelocidadMaxima)); pl.Add(Projections.Avg <Datamart>(dm => dm.AverageSpeed).WithAlias(() => ta.VelocidadPromedio)); pl.Add(Projections.Group <Datamart>(dm => dm.Vehicle.Id).WithAlias(() => ta.IdVehiculo)); ICriteria crit = GetDatamartCriteria(0, dc, pl, null, typeof(TransportActivity)); IList <TransportActivity> results = crit.List <TransportActivity>(); var cocheDAO = new CocheDAO(); foreach (TransportActivity r in results) { Coche coche = cocheDAO.FindById(r.Id); r.HsInfraccion /= 60; r.Transport = coche.Transportista.Descripcion; r.CentroDeCostos = coche.CentroDeCostos != null ? coche.CentroDeCostos.Descripcion : null; r.TipoVehiculo = coche.TipoCoche != null ? coche.TipoCoche.Descripcion : null; } return(results); }
protected IList <T> GetAllGeneric <T>(List <FilterOption> filters, int pageNumber, int pageSize, string sortBy, string sortDirection, List <string> selectColumnsList = null) { ICriteria query = GetQueryCondition <T>(filters); selectColumnsList = selectColumnsList ?? new List <string>(); if (selectColumnsList.Any()) { ProjectionList projectionList = Projections.ProjectionList(); foreach (var column in selectColumnsList) { projectionList.Add(Projections.Property(column), column); } query.SetProjection(projectionList); } string sortByText = string.Empty; var property = typeof(T).GetProperties().SingleOrDefault(prop => prop.Name.ToLower() == sortBy.ToLower()); if (property != null) { sortByText = property.Name; } Order order = sortDirection.ToLower() == "asc" ? Order.Asc(sortByText) : Order.Desc(sortByText); return(query.SetFirstResult((pageNumber - 1) * pageSize) .SetMaxResults(pageSize).AddOrder(order) .SetResultTransformer(Transformers.AliasToBean(typeof(T))) .List <T>()); }
public IDictionary <string, int> getYearlyStudentMap() { Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(StatisticsManagerImpl)", null, Constant.LOGTYPE_INFO); DetachedCriteria criteria = DetachedCriteria.For <Entity_PlacementDetails>(); criteria.CreateAlias("stuObj", "student"); ProjectionList projectionList = Projections.ProjectionList(); projectionList.Add(Projections.GroupProperty(Projections.Property("student.myConfigObj.currentBatch"))); projectionList.Add(Projections.Count(Projections.Property("detailsId"))); criteria.SetProjection(projectionList); criteria.Add(Restrictions.Eq("student.myConfigObj.currentDegree", Common.loggedUser.myConfigObj.currentDegree)); IList list = persistence.findByCriteria(criteria); if (list != null && list.Count > 0) { IDictionary <string, int> resultMap = new Dictionary <string, int>(); foreach (Object[] item in list) { resultMap.Add(item[0].ToString(), Convert.ToInt32(item[1])); } return(resultMap); } else { return(null); } }
/// <summary> /// Adds the specified property to the projection list. /// </summary> /// <param name="list"> /// The projection list. /// </param> /// <param name="property"> /// The property. /// </param> /// <param name="data"> /// A <see cref="QueryHelperData" /> instance. /// </param> /// <typeparam name="TSource"> /// The <see cref="System.Type" /> of the source entity. /// </typeparam> /// <typeparam name="TProperty"> /// The <see cref="System.Type" /> of the property. /// </typeparam> /// <returns> /// The <see cref="ProjectionList" /> instance. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="list" /> is null. /// </exception> public static ProjectionList AddProperty <TSource, TProperty> ( this ProjectionList list, Expression <Func <TSource, TProperty> > property, QueryHelperData data ) { if (list == null) { throw new ArgumentNullException("list"); } IProjection projection = ProjectionHelper.GetProjection(property, data); string alias = null; var propertyProjection = projection as IPropertyProjection; if (propertyProjection != null) { alias = propertyProjection.PropertyName; } list.Add(projection, alias); return(list); }
protected override void SetCriteria() { DetachedCriteria criteria = DetachedCriteria.For(typeof(CycleCountResult)); criteria.CreateAlias("CycleCount", "cc"); criteria.CreateAlias("cc.Location", "l"); #region Customize SecurityHelper.SetRegionSearchCriteria(criteria, "l.Region.Code", this.CurrentUser.Code); //区域权限 OrderHelper.SetActiveOrderStatusCriteria(criteria, "cc.Status"); //状态 #endregion #region Select Parameters CriteriaHelper.SetPartyCriteria(criteria, "l.Region.Code", this._criteriaParam); CriteriaHelper.SetLocationCriteria(criteria, "cc.Location.Code", this._criteriaParam); CriteriaHelper.SetStartDateCriteria(criteria, "cc.EffectiveDate", this._criteriaParam); CriteriaHelper.SetEndDateCriteria(criteria, "cc.EffectiveDate", this._criteriaParam); CriteriaHelper.SetStorageBinCriteria(criteria, "StorageBin.Code", this._criteriaParam); CriteriaHelper.SetItemCriteria(criteria, "Item.Code", this._criteriaParam); CriteriaHelper.SetOrderNoCriteria(criteria, "CycleCount.Code", this._criteriaParam, MatchMode.Start); #endregion #region Projections ProjectionList projectionList = Projections.ProjectionList() .Add(Projections.Max("Id").As("Id")) .Add(Projections.Sum("Qty").As("Qty")) .Add(Projections.Sum("InvQty").As("InvQty")) .Add(Projections.Sum("DiffQty").As("DiffQty")) .Add(Projections.Count("HuId").As("Cartons")) .Add(Projections.GroupProperty("Item").As("Item")); if (!this._criteriaParam.ClassifiedOrderNo) { projectionList.Add(Projections.GroupProperty("CycleCount").As("CycleCount")); } if (!this._criteriaParam.ClassifiedLocation) { projectionList.Add(Projections.GroupProperty("cc.Location").As("Location")); } if (!this._criteriaParam.ClassifiedBin) { projectionList.Add(Projections.GroupProperty("StorageBin").As("StorageBin"));//库格 } if (!this._criteriaParam.ClassifiedHuId) { projectionList.Add(Projections.GroupProperty("HuId").As("HuId")); //条码 projectionList.Add(Projections.GroupProperty("LotNo").As("LotNo")); //批号 projectionList.Add(Projections.GroupProperty("ReferenceLocation").As("ReferenceLocation")); //参考库位 projectionList.Add(Projections.GroupProperty("DiffReason").As("DiffReason")); //差异原因 } criteria.SetProjection(projectionList); criteria.SetResultTransformer(Transformers.AliasToBean(typeof(CycleCountResult))); #endregion DetachedCriteria selectCountCriteria = CloneHelper.DeepClone <DetachedCriteria>(criteria); selectCountCriteria.SetProjection(Projections.Count("Id")); SetSearchCriteria(criteria, selectCountCriteria); }
public ICriteria AddTheProjections(ICriteria criteria) { ProjectionList projections = Projections.ProjectionList(); _columns.Each(column => column.AddProjection(projections)); return(criteria.SetProjection(projections)); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="projections"></param> /// <returns></returns> public T Get(object id, ProjectionList projections) { return(_sessionFactory .GetCurrentSession() .CreateCriteria(typeof(T)) .SetProjection(projections) .UniqueResult <T>()); }
protected virtual void SetTransformer(ICriteria criteria, bool requiredTransform, ProjectionList projectionList, IResultTransformer transformer) { if (requiredTransform || projectionList.Length != 0) { criteria.SetResultTransformer(transformer); } }
static ViewModelsReader() { // TODO: this could be handled by IoC container not class itself. But maybe it's beter to store this information in static fields? Think about. persistenceModelDescription = PersistenceModelPropertiesDescriptionGenerator.GenerateDescription(typeof(TPersistenceModel)); viewModelToPersistenceModelMap = ViewModelToPersistenceModelPropertyNamesMapsGenerator.Generate( typeof(TGridModel), persistenceModelDescription); projectionsList = ProjectionsGenerator.GenerateProjectionsList(viewModelToPersistenceModelMap); }
private ICriteria GetDatamartCriteria(int top, DetachedCriteria dc, ProjectionList pl, Order order, Type T) { ICriteria crit = GetDatamartCriteria(top, dc, pl, order); crit.SetResultTransformer(Transformers.AliasToBean(T)); return(crit); }
public ICollection <ProjT> ReportAll <ProjT>(ProjectionList projectionList, bool distinctResults) { using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches) { ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, null, CreateCriteria); return(DoReportAll <ProjT>(crit, projectionList, distinctResults)); } }
public IList <Trilha> ObterTrilhas() { ICriteria criteria = repositorio.session.CreateCriteria(typeof(ViewUsuarioTrilhaAtividadeFormativaParticipacao), "vw"); ProjectionList projList = Projections.ProjectionList(); projList.Add(Projections.Distinct(Projections.Property <ViewUsuarioTrilhaAtividadeFormativaParticipacao>(d => d.TrilhaOrigem))); criteria.SetProjection(projList); return(criteria.List <Trilha>()); }
public ICollection <ProjT> ReportAll <ProjT>(DetachedCriteria criteria, ProjectionList projectionList) { using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches) { ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria, CreateCriteria); return(DoReportAll <ProjT>(crit, projectionList)); } }
public ICollection <ProjT> ReportAll <ProjT>(ProjectionList projectionList, Order[] orders, params ICriterion[] criteria) { using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches) { ICriteria crit = RepositoryHelper <T> .CreateCriteriaFromArray(action.Value, criteria, CreateCriteria, orders); return(DoReportAll <ProjT>(crit, projectionList)); } }
/// <summary> /// Adds the specified property to the projection list. /// </summary> /// <param name="list"> /// The projection list. /// </param> /// <param name="property"> /// The property. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <returns> /// The <see cref="ProjectionList" /> instance. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="list" /> is null. /// </exception> public static ProjectionList AddProperty(this ProjectionList list, string property, string alias) { if (list == null) { throw new ArgumentNullException("list"); } return(list.Add(Projections.Property(property), alias)); }
/// <summary> /// Adds the specified projection list. /// </summary> /// <typeparam name="TFrom">The type of from.</typeparam> /// <typeparam name="TTo">The type of to.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="projectionList">The projection list.</param> /// <param name="projectionExpression">The projection expression.</param> /// <param name="aliasExpression">The alias expression.</param> /// <returns>A <see cref="ProjectionList"/></returns> public static ProjectionList Add <TFrom, TTo, TProperty> ( this ProjectionList projectionList, Expression <Func <TFrom, object> > projectionExpression, Expression <Func <TTo, TProperty> > aliasExpression) { var projection = Projections.Property(projectionExpression); return(projectionList.Add(projection, PropertyUtil.ExtractPropertyName(aliasExpression))); }
public static ICriteria ProjectToViewModel <TPersistenceModel, TGridModel>( this IQueryOver <TPersistenceModel, TPersistenceModel> query, ProjectionList projectionsList) { query.UnderlyingCriteria .SetProjection(projectionsList) .SetResultTransformer(Transformers.AliasToBean <TGridModel>()); return(query.UnderlyingCriteria); }