Example #1
0
        public RootQueryBuilder <T> Where(Expression <Func <T, bool> > whereExp)
        {
            var condBuilder = new WhereConditionGeneratorTreeVisitor();

            condBuilder.AddType(RootTable, RootEntityType);
            condBuilder.Visit(whereExp);
            WhereCondition condition = condBuilder.Fragment;

            Qb.Where(condition);
            return(this);
        }
Example #2
0
        /// <summary>
        /// Joins the table of name <paramref name="joined_table_name"/>, represented by type <typeparamref name="JT" /> to the root entity, the join condition
        /// being expressed in <paramref name="joinCondition"/>.
        /// </summary>
        /// <param name="joined_table_name">The real name of the table to be joined, as it is in the database.</param>
        /// <param name="joinType">The type of join (inner, outer etc.)</param>
        /// <typeparam name="JT">The type that represents the newly joined table.</typeparam>
        public RootQueryBuilder <T> Join <JT>(string joined_table_name, Expression <Func <T, JT, bool> > joinCondition, JoinType joinType)
        {
            if (QueriedTables.ContainsKey(joined_table_name))
            {
                throw new InvalidOperationException("This table has already been queried/joined. Please use a method that allows you to join to the same table more than once.");
            }

            var conditionBuilder = new WhereConditionGeneratorTreeVisitor();

            conditionBuilder.AddType(RootTable, RootEntityType);
            conditionBuilder.AddType(joined_table_name, typeof(JT));
            conditionBuilder.Visit(joinCondition);
            WhereCondition condFragment = conditionBuilder.Fragment;

            Qb.Join(joined_table_name, condFragment, joinType);

            return(this);
        }
        protected virtual Expression VisitAndOr(BinaryExpression node)
        {
            var leftCondition = new WhereConditionGeneratorTreeVisitor(TableEntities);

            leftCondition.Visit(node.Left);
            var rightCondition = new WhereConditionGeneratorTreeVisitor(TableEntities);

            rightCondition.Visit(node.Right);

            switch (node.NodeType)
            {
            case ExpressionType.AndAlso:
                Fragment.And(leftCondition.Fragment).And(rightCondition.Fragment);
                break;

            case ExpressionType.OrElse:
                Fragment.Or(leftCondition.Fragment).Or(rightCondition.Fragment);
                break;
            }

            return(node);
        }