示例#1
0
        /// <summary>
        /// Add order expressed as a lambda expression
        /// </summary>
        /// <param name="criteria">criteria instance</param>
        /// <param name="expression">Lambda expression</param>
        /// <param name="orderDelegate">Order delegate (direction)</param>
        /// <returns>criteria instance</returns>
        public static ICriteria AddOrder(this ICriteria criteria,
                                         Expression <Func <object> > expression,
                                         Func <string, Order> orderDelegate)
        {
            Order order = ExpressionProcessor.ProcessOrder(expression, orderDelegate);

            criteria.AddOrder(order);
            return(criteria);
        }
示例#2
0
        /// <summary>
        /// Join an association, assigning an alias to the joined entity
        /// </summary>
        /// <param name="criteria">criteria instance</param>
        /// <param name="expression">Lambda expression returning association path</param>
        /// <param name="alias">Lambda expression returning alias reference</param>
        /// <returns>criteria instance</returns>
        public static ICriteria CreateAlias(this ICriteria criteria,
                                            Expression <Func <object> > expression,
                                            Expression <Func <object> > alias)
        {
            string path           = ExpressionProcessor.FindMemberExpression(expression.Body);
            string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body);

            return(criteria.CreateAlias(path, aliasContainer));
        }
        /// <summary>
        /// Join an association, assigning an alias to the joined entity
        /// </summary>
        /// <param name="criteria">criteria instance</param>
        /// <param name="expression">Lambda expression returning association path</param>
        /// <param name="alias">Lambda expression returning alias reference</param>
        /// <param name="joinType">The type of join to use</param>
        /// <returns>criteria instance</returns>
        public static DetachedCriteria CreateAlias(this DetachedCriteria criteria,
                                                   Expression <Func <object> > expression,
                                                   Expression <Func <object> > alias,
                                                   JoinType joinType)
        {
            string path           = ExpressionProcessor.FindMemberExpression(expression.Body);
            string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body);

            return(criteria.CreateAlias(path, aliasContainer, joinType));
        }
示例#4
0
        /// <summary>
        /// Create a DetachedCriteria with a strongly typed alias
        /// </summary>
        /// <param name="alias">Lambda expression returning alias reference</param>
        /// <returns>Newly created DetachedCriteria</returns>
        public static DetachedCriteria Create(Expression <Func <object> > alias)
        {
            string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body);

            return(DetachedCriteria.For <T>(aliasContainer));
        }
示例#5
0
        /// <summary>
        /// Return the negation of an expression
        /// </summary>
        /// <param name="expression">Lambda expression</param>
        /// <returns>A NHibernate.Criterion.NotExpression.</returns>
        public static ICriterion Not(Expression <Func <bool> > expression)
        {
            ICriterion criterion = ExpressionProcessor.ProcessExpression(expression);

            return(Restrictions.Not(criterion));
        }
示例#6
0
        /// <summary>
        /// Create an ICriterion for the supplied LambdaExpression
        /// </summary>
        /// <param name="expression">lambda expression</param>
        /// <returns>return NHibernate.Criterion.ICriterion</returns>
        public static ICriterion CriterionFor(Expression <Func <bool> > expression)
        {
            ICriterion criterion = ExpressionProcessor.ProcessExpression(expression);

            return(criterion);
        }
示例#7
0
        /// <summary>
        /// Apply an "is not empty" constraint to the named property
        /// </summary>
        /// <param name="expression">lambda expression returning type's property</param>
        /// <returns>A NHibernate.Criterion.IsNotEmptyExpression.</returns>
        public static ICriterion IsNotEmpty(Expression <Func <IEnumerable> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(Restrictions.IsNotEmpty(property));
        }
示例#8
0
        /// <summary>
        /// Apply an "is not null" constraint to the named property
        /// </summary>
        /// <param name="expression">lambda expression returning type's property</param>
        /// <returns>A NHibernate.Criterion.NotNullExpression.</returns>
        public static ICriterion IsNotNull(Expression <Func <object> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(Restrictions.IsNotNull(property));
        }
        /// <summary>
        /// Create ICriterion for (all) subquery expression using lambda syntax
        /// </summary>
        /// <param name="expression">lambda expression</param>
        /// <returns>NHibernate.ICriterion.AbstractCriterion</returns>
        public static AbstractCriterion WhereAll(Expression <Func <bool> > expression)
        {
            AbstractCriterion criterion = ExpressionProcessor.ProcessSubquery(LambdaSubqueryType.All, expression);

            return(criterion);
        }
        /// <summary>
        /// Create ICriterion for subquery expression using lambda syntax
        /// </summary>
        /// <typeparam name="T">type of property</typeparam>
        /// <param name="expression">lambda expression</param>
        /// <returns>NHibernate.ICriterion.AbstractCriterion</returns>
        public static AbstractCriterion Where <T>(Expression <Func <T, bool> > expression)
        {
            AbstractCriterion criterion = ExpressionProcessor.ProcessSubquery <T>(LambdaSubqueryType.Exact, expression);

            return(criterion);
        }
        /// <summary>
        /// Create a ICriterion for the specified property subquery expression
        /// </summary>
        /// <param name="expression">lambda expression</param>
        /// <returns>returns LambdaSubqueryBuilder</returns>
        public static LambdaSubqueryBuilder Property(Expression <Func <object> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(new LambdaSubqueryBuilder(property));
        }
        /// <summary>
        /// Count projection
        /// </summary>
        /// <typeparam name="T">generic type</typeparam>
        /// <param name="expression">lambda expression</param>
        /// <returns>return NHibernate.Criterion.CountProjection</returns>
        public static CountProjection Count <T>(Expression <Func <T, object> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(Projections.Count(property));
        }
        /// <summary>
        /// Average projection
        /// </summary>
        /// <param name="expression">lambda expression</param>
        /// <returns>return NHibernate.Criterion.AggregateProjection</returns>
        public static AggregateProjection Avg(Expression <Func <object> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(Projections.Avg(property));
        }
        /// <summary>
        /// Create an IProjection for the specified property expression
        /// </summary>
        /// <param name="expression">lambda expression</param>
        /// <returns>return NHibernate.Criterion.PropertyProjection</returns>
        public static PropertyProjection Property(Expression <Func <object> > expression)
        {
            string property = ExpressionProcessor.FindMemberExpression(expression.Body);

            return(Projections.Property(property));
        }