コード例 #1
0
        private Clause CreateClauseFromExpression(BinaryExpression binaryExp)
        {
            if (binaryExp.NodeType == ExpressionType.AndAlso || binaryExp.NodeType == ExpressionType.OrElse)
            {
                BinaryExpression leftExpression = binaryExp.Left as BinaryExpression;
                if (leftExpression == null)
                {
                    throw new UnsupportedExpressionException("Expression in left side is invalid.", nameof(BinaryExpression));
                }
                BinaryExpression rightsExpression = binaryExp.Right as BinaryExpression;
                if (rightsExpression == null)
                {
                    throw new UnsupportedExpressionException("Expression in right side is invalid.", nameof(BinaryExpression));
                }

                return(new LogicalClause(
                           SqlBuilderHelper.MapExpressionTypeToBooleanOperation(binaryExp.NodeType),
                           CreateClauseFromExpression(leftExpression),
                           CreateClauseFromExpression(rightsExpression)
                           ));
            }

            return(new ComparisonClause(
                       SqlBuilderHelper.MapExpressionTypeToBinaryOperation(binaryExp.NodeType),
                       SqlBuilderHelper.GetClassNameFromExpression(binaryExp.Left),
                       SqlBuilderHelper.GetMemberNameFromExpression(binaryExp.Left),
                       SqlBuilderHelper.GetRightValueFromBinaryExpression(binaryExp)
                       ));
        }
コード例 #2
0
        public SelectDeclaration <TSource> Field <T>(Expression <Func <T, object> > fieldSelector, string alias)
        {
            Field field = new Field(typeof(T).Name, SqlBuilderHelper.GetMemberNameFromExpression(fieldSelector), alias);

            _selectItems.Add(new FieldSelectItem(field));
            return(this);
        }
コード例 #3
0
        public OrderByDeclaration <TSource> OrderBy <TCustom>(Expression <Func <TCustom, object> > fieldSelector, OrderDirection orderDirection)
        {
            Field field = new Field(typeof(TCustom).Name, SqlBuilderHelper.GetMemberNameFromExpression(fieldSelector));

            _orderItems.Add(new OrderByClauseItem(field, orderDirection));
            return(this);
        }
コード例 #4
0
        public SelectFollowingBuilder <T> Select <T>(TableHint hints, IEnumerable <Expression <Func <T, object> > > fieldSelectors)
        {
            IEnumerable <Field> fields = fieldSelectors.Select(
                f => new Field(typeof(T).Name, SqlBuilderHelper.GetMemberNameFromExpression(f))
                );

            return(Select <T>(hints, fields));
        }
コード例 #5
0
 public ComparisonClause(ComparisonOperator operation, Expression <Func <T, object> > fieldSelector, object value)
 {
     Initialize(
         operation,
         typeof(T).Name,
         SqlBuilderHelper.GetMemberNameFromExpression(fieldSelector),
         value
         );
 }
コード例 #6
0
        public ComparisonClause(Expression <Func <T, object> > expression)
        {
            BinaryExpression binaryExp = SqlBuilderHelper.ConvertToBinaryExpression(expression);

            Initialize(
                SqlBuilderHelper.MapExpressionTypeToBinaryOperation(binaryExp.NodeType),
                typeof(T).Name,
                SqlBuilderHelper.GetMemberNameFromExpression(binaryExp.Left),
                SqlBuilderHelper.GetRightValueFromBinaryExpression(binaryExp)
                );
        }
コード例 #7
0
        protected SelectDeclaration <TSource> FieldAggregation <TCustom>(AggregateFunction aggregateFunction, Expression <Func <TCustom, object> > fieldSelector, string alias = null)
        {
            Field field = null;

            if (fieldSelector != null)
            {
                field = new Field(typeof(TCustom).Name, SqlBuilderHelper.GetMemberNameFromExpression(fieldSelector));
            }
            _selectItems.Add(new FieldAggregateSelectItem(aggregateFunction, field, alias));
            return(this);
        }
コード例 #8
0
        public WhereDeclaration <TSource> Comparison <TCustom>(Expression <Func <TCustom, object> > fieldSelector, ComparisonOperator comparisonOperator, object value)
        {
            ComparisonClause clause = new ComparisonClause(
                comparisonOperator,
                typeof(TCustom).Name,
                SqlBuilderHelper.GetMemberNameFromExpression(fieldSelector),
                value
                );

            _clauses.Add(clause);
            return(this);
        }
コード例 #9
0
        public UpdateDeclaration <T> Set(Expression <Func <T, object> > fieldExpression, object value, AssignmentOperator assignmentOperator)
        {
            if (fieldExpression == null)
            {
                throw new ArgumentNullException(nameof(fieldExpression));
            }

            string fieldName = SqlBuilderHelper.GetMemberNameFromExpression(fieldExpression);

            if (_updateItems.Any(u => string.Compare(u.FieldName, fieldName, true) == 0))
            {
                throw new ArgumentException($"The column '{fieldName}' is specified more than once in the UPDATE clause. A column cannot be assigned more than one value in the same clause.");
            }
            _updateItems.Add(new UpdateClauseItem(fieldName, value, assignmentOperator));

            return(this);
        }
コード例 #10
0
        private Dictionary <string, object> GetFieldsToUpsertFromExpression <T>(IEnumerable <Expression <Func <T, object> > > fieldValues)
        {
            if (fieldValues == null || !fieldValues.Any())
            {
                throw new ArgumentNullException(nameof(fieldValues));
            }

            Dictionary <string, object> propsToInsert = new Dictionary <string, object>();

            foreach (Expression <Func <T, object> > item in fieldValues)
            {
                BinaryExpression binaryExp = SqlBuilderHelper.ConvertToBinaryExpression(item);
                string           fieldName = SqlBuilderHelper.GetMemberNameFromExpression(binaryExp.Left);
                object           value     = SqlBuilderHelper.GetRightValueFromBinaryExpression(binaryExp);
                propsToInsert.Add(fieldName, value);
            }

            return(propsToInsert);
        }
コード例 #11
0
        public InClause(Expression <Func <TTable, TMember> > memberExpression, IEnumerable <TMember> value)
        {
            string fieldName = SqlBuilderHelper.GetMemberNameFromExpression(memberExpression.Body);

            Initialize(typeof(TTable).Name, fieldName, value);
        }