示例#1
0
        public IList <T> QueryPaging <T>(NHibernate.Criterion.ICriterion expression,
                                         NHibernate.Criterion.Order[] orders, int pageIndex, int pageSize,
                                         out int recordCount) where T : class
        {
            recordCount = 0;
            ICriteria criteria = session.CreateCriteria <T>();

            if (expression != null)
            {
                criteria.Add(expression);
            }
            ICriteria pageCriteria = CriteriaTransformer.Clone(criteria);

            recordCount = criteria.SetProjection(Projections.RowCount()).UniqueResult <int>();
            if (orders != null)
            {
                foreach (var order in orders)
                {
                    pageCriteria.AddOrder(order);
                }
            }
            pageCriteria.SetFirstResult((pageIndex - 1) * pageSize);
            pageCriteria.SetMaxResults(pageSize);
            return(pageCriteria.List <T>());
        }
示例#2
0
        /// <summary>
        /// Gets the entity list from respersitory.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expressions">The criterion expressions,for example:new ICriterion[]{Restriction.Eq("AField","xy")}.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public IList <T> GetList <T>(Hib.Criterion.ICriterion expressions, string associatePath, string alias, params Hib.Criterion.Order[] orders)
        {
            try
            {
                OpenConnect();
                Hib.ICriteria criteria = _Session.CreateCriteria(typeof(T));
                criteria.CreateAlias(associatePath, alias);
                if (expressions != null)
                {
                    criteria.Add(expressions);
                }

                foreach (Hib.Criterion.Order o in orders)
                {
                    criteria.AddOrder(o);
                }
                return(criteria.List <T>());
            }
            catch (Exception ex)
            {
                LogExepttion(ex);
                throw;
            }
            finally
            {
                Disconnect();
            }
        }
示例#3
0
        public int GetCount <T>(NHibernate.Criterion.ICriterion expression) where T : class
        {
            ICriteria criteria = session.CreateCriteria <T>();

            if (expression != null)
            {
                criteria.Add(expression);
            }
            return(criteria.SetProjection(Projections.RowCount()).UniqueResult <int>());
        }
示例#4
0
 public static void CriteriaAddFilterAndSetFirstResultAndMaxResults(ICriteria criteria, Dddml.Support.Criterion.ICriterion filter, int firstResult, int maxResults)
 {
     if (filter != null)
     {
         NHibernateICriterion hc = CriterionUtils.ToNHibernateCriterion(filter);
         criteria.Add(hc);
     }
     criteria.SetFirstResult(firstResult);
     criteria.SetMaxResults(maxResults);
 }
示例#5
0
 ///// <summary>
 ///// If a type is nullable of we must
 ///// </summary>
 ///// <param name="type"></param>
 ///// <returns></returns>
 //private System.Type GetTypeCheckForNullable(System.Type type) {
 //if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {…}
 //w.FinalType.GetGenericArguments()
 //}
 /// <summary>
 /// Ok we have a sql function, the inner token already created a criterion we
 /// only needs to configureIt
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 private WalkedToken WalkSqlFunction(WalkedToken left, WalkedToken right)
 {
     CustomCriterion.SqlFunctionCriterion crit = (CustomCriterion.SqlFunctionCriterion)left.Criterion;
     //configureSqlCustomCriterion(crit);
     NHibernate.Criterion.ICriterion outCriterion = expCreator("", null);
     crit.StrOperator = outCriterion.GetType().GetProperty(
         "Op", BindingFlags.NonPublic | BindingFlags.Instance)
                        .GetValue(outCriterion, null) as String;
     crit.ValueToCompareTo = right.GetValue <Object>();
     return(left);
 }
 public virtual long GetCount(Dddml.Support.Criterion.ICriterion filter)
 {
     var criteria = CurrentSession.CreateCriteria<SellableInventoryItemState>();
     criteria.SetProjection(Projections.RowCountInt64());
     if (filter != null)
     {
         NHibernateICriterion hc = CriterionUtils.ToNHibernateCriterion(filter);
         criteria.Add(hc);
     }
     AddNotDeletedRestriction(criteria);
     return criteria.UniqueResult<long>();
 }
        public virtual long GetCount <T>(Dddml.Support.Criterion.ICriterion filter) where T : class, IPartyState
        {
            var criteria = CurrentSession.CreateCriteria <T>();

            criteria.SetProjection(Projections.RowCountInt64());
            if (filter != null)
            {
                NHibernateICriterion hc = CriterionUtils.ToNHibernateCriterion(filter);
                criteria.Add(hc);
            }
            AddNotDeletedRestriction(criteria);
            return(criteria.UniqueResult <long>());
        }
示例#8
0
        public virtual long GetCount(Dddml.Support.Criterion.ICriterion filter)
        {
            var criteria = CurrentSession.CreateCriteria <AttributeSetInstanceExtensionFieldGroupState>();

            criteria.SetProjection(Projections.RowCountInt64());
            if (filter != null)
            {
                NHibernateICriterion hc = CriterionUtils.ToNHibernateCriterion(filter);
                criteria.Add(hc);
            }
            AddNotDeletedRestriction(criteria);
            return(criteria.UniqueResult <long>());
        }
示例#9
0
        /// <summary>
        /// Gets the distict list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="distictPropertys">The distict propertys.</param>
        /// <param name="expressions">The expressions.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public IList <valT> GetDistinctList <T, valT>(string[] distictPropertys, Hib.Criterion.ICriterion expressions, params Hib.Criterion.Order[] orders)
        {
            try
            {
                OpenConnect();
                Hib.ICriteria criteria = _Session.CreateCriteria(typeof(T));
                if (distictPropertys != null)
                {
                    ProjectionList projects = Projections.ProjectionList();
                    foreach (string p in distictPropertys)
                    {
                        projects.Add(Projections.Property(p));
                    }
                    criteria.SetProjection(Projections.Distinct(projects));
                }
                else
                {
                    throw new Exception("the disctinct property can't be null.");
                }
                if (expressions != null)
                {
                    criteria.Add(expressions);
                }

                foreach (Hib.Criterion.Order o in orders)
                {
                    criteria.AddOrder(o);
                }
                return(criteria.List <valT>());
            }
            catch (Exception ex)
            {
                LogExepttion(ex);
                throw;
            }
            finally
            {
                Disconnect();
            }
        }
示例#10
0
 public IList <T> QueryPaging <T>(NHibernate.Criterion.ICriterion expression, int pageIndex, int pageSize, out int recordCount) where T : class
 {
     return(QueryPaging <T>(expression, new Order[] { }, pageIndex, pageSize, out recordCount));
 }
示例#11
0
 public IList <T> Query <T>(NHibernate.Criterion.ICriterion expression, Action <NHibernate.ICriteria> action) where T : class
 {
     return(Query <T>(new ICriterion[] { expression }, action));
 }
示例#12
0
 public IList <T> Query <T>(NHibernate.Criterion.ICriterion expression) where T : class
 {
     return(Query <T>(expression, null));
 }