Example #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)
                       ));
        }
        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)
                );
        }
Example #3
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);
        }