Пример #1
0
 /// <summary>
 /// Perform each function that is applicable in the current gate context. The input parameter
 /// is passed to the first applicable function, and the result of that function is used as the input
 /// for the next applicable function, etc. This allows for chaining multiple functions, each having
 /// an opportunity to modify the input.
 /// </summary>
 /// <param name="context">gate context</param>
 /// <param name="input">the input object</param>
 /// <param name="mode">mode to run the gated code in</param>
 /// <param name="functions">array of gated functions</param>
 /// <typeparam name="T">the return type of the function</typeparam>
 /// <returns>instance of T (default if no applicable action found)</returns>
 public static T PerformEachFunction <T>(this IGateContext context, GatedCode.Modes mode, T input, params GatedFunc <T, T>[] functions)
 {
     Array.ForEach(functions,
                   (function) =>
     {
         input = SelectFunction(context, mode, function)(input);
     }
                   );
     return(input);
 }
Пример #2
0
        public string AddHaving(string tableName, string fieldName, SelectFunction selectFunction, string opr, string parameter)
        {
            var func = selectFunction.ToString();

            _componentList.Add(string.Format("{2}({0}.{1}) {3} {4}", tableName, fieldName, func, opr, _adapter.Parameter(parameter)));
            return(parameter);
        }
Пример #3
0
        public void HavingWithCount <T>(Expression <Func <T, object> > expression, SelectFunction selectFunction, Expression <Func <int, bool> > cmp)
        {
            var fieldName = GetColumnName(GetMemberExpression(expression.Body));
            var tmpcmp    = GetBinaryExpression(cmp.Body);
            var opr       = _operationDictionary[tmpcmp.NodeType];
            var value     = GetExpressionValue(tmpcmp.Right);

            _builder.Having(GetTableName <T>(), fieldName, selectFunction, opr, value);
        }
Пример #4
0
        internal void Aggregate(LambdaExpression expression, SelectFunction selectFunction)
        {
            expression.ThrowIfNull(nameof(expression));

            var fieldName  = TableInfo.GetColumnName(expression.Body.GetMemberExpression());
            var memberNode = new MemberNode {
                TableName = TableName, FieldName = fieldName
            };
            var selectionString = SqlFormatter.SelectAggregate(memberNode, selectFunction.ToString());

            Context.Selection.Add(selectionString);
        }
 public void Select(string tableName, string fieldName, string alias, SelectFunction selectFunction)
 {
     if (string.IsNullOrEmpty(alias) || fieldName == alias)
     {
         Select(tableName, fieldName, selectFunction);
     }
     else
     {
         var selectionString = $"{selectFunction}({Adapter.Field(tableName, fieldName)}) {Adapter.Alias(alias)}";
         SelectionList.Add(selectionString);
     }
 }
        public void Select(string tableName, string fieldName, SelectFunction selectFunction, string alias = null)
        {
            string selectionString = null;

            if (string.IsNullOrEmpty(alias))
            {
                selectionString = string.Format("{0}({1})", selectFunction.ToString(), Adapter.Field(tableName, fieldName));
            }
            else
            {
                selectionString = string.Format("{0}({1}) AS {2}", selectFunction.ToString(), Adapter.Field(tableName, fieldName), alias);
            }
            _selectionList.Add(selectionString);
        }
        public void Select(string tableName, string fieldName, SelectFunction selectFunction, string aliasName)
        {
            string name = string.IsNullOrEmpty(aliasName) ? fieldName : aliasName;

            name = _adapter.Field(name);

            var fname = fieldName;

            if (fieldName != "*")
            {
                fname = _adapter.Field(tableName, fieldName);
            }
            var selectionString = string.Format("{0}({1}) AS {2}", selectFunction.ToString(), fname, name);

            _selectionList.Add(selectionString);
        }
Пример #8
0
        internal void Select(string tableName, string columnName, SelectFunction selectFunction, string tableAlias, string columnAlias)
        {
            var functionNoHasColumnName  = !String.IsNullOrEmpty(columnName);
            var functionName             = selectFunction.ToString();
            var existsAlias              = !String.IsNullOrEmpty(columnAlias);
            var tableNameToUse           = String.IsNullOrEmpty(tableAlias) ? tableName : tableAlias;
            var columnNameToUserFunction = functionNoHasColumnName ? _sqlAdapter.GetColumnName(tableNameToUse, columnName) : "1";
            var functionClause           = new StringBuilder($"{functionName.ToUpper()}({columnNameToUserFunction}) ");

            if (existsAlias)
            {
                functionClause.Append($"AS {columnAlias} ");
            }

            _sqlQueryBuilderExtension.AddFunctionsName(functionClause.ToString());
        }
Пример #9
0
        private void AddHavingClause(ClauseInput clauseInput, SelectFunction selectFunction)
        {
            var havingEpression = $"{selectFunction.ToString().ToUpper()}({clauseInput.Column}) {clauseInput.Operation} {clauseInput.ParameterFormated}";

            _havingClause.Add(havingEpression);
        }
Пример #10
0
        public void Having(string tableName, string fieldName, SelectFunction selectFunction, string opr, object value)
        {
            var paramId = _havingBuilder.AddHaving(tableName, fieldName, selectFunction, opr, NextParamId());

            AddParameter(paramId, value);
        }
Пример #11
0
        /// <summary>
        /// Method to add 'HAVING' function in select.
        /// </summary>
        /// <typeparam name="THaving">Indicates a new type to use for table columns.</typeparam>
        /// <param name="conditionsExp">Indicates column to use in the 'HAVING' clause, through expression.</param>
        /// <param name="tableAlias">Use this parameter when it is necessary to reference the table by alias.</param>
        /// <returns>Returns the instance of FluentSqlBuilder<TTable>. Corresponds to the root instance.</returns>
        public FluentSqlBuilder <TTable> Having <THaving>(SelectFunction selectFunction, Expression <Func <THaving, bool> > conditionsExp, string tableAlias = null)
        {
            _resolver.AddHaving(tableAlias, conditionsExp, TargetClauseType.Having, selectFunction);

            return(this);
        }
        public void AddHaving <TTable>(string tableAlias, Expression <Func <TTable, bool> > expressionFilter, TargetClauseType targetClauseType, SelectFunction selectFunction)
        {
            var expressionTree = GetExpressionTree(expressionFilter);

            _lambdaResolverExtension.BuildSelect(expressionTree, tableAlias, targetClauseType, selectFunction);
        }
 public void SelectWithFunction <T>(Expression <Func <T, object> > expression, SelectFunction selectFunction)
 {
     SelectWithFunction <T>(expression.Body, selectFunction);
 }
        private void SelectWithFunction <T>(Expression expression, SelectFunction selectFunction)
        {
            var fieldName = GetColumnName(GetMemberExpression(expression));

            Builder.Select(GetTableName <T>(), fieldName, selectFunction);
        }
Пример #15
0
 /// <summary>
 /// Perform a function that is applicable in the current gate context
 /// </summary>
 /// <param name="context">gate context</param>
 /// <param name="mode">mode to run the gated code in</param>
 /// <param name="functions">array of gated functions</param>
 /// <typeparam name="T">the return type of the function</typeparam>
 /// <returns>instance of T (default if no applicable action found)</returns>
 public static Task <T> PerformFunction <T>(this IGateContext context, GatedCode.Modes mode, params GatedAsyncFunc <T>[] functions) => SelectFunction(context, mode, null, functions)();
Пример #16
0
 /// <summary>
 /// Perform a function that is applicable in the current gate context
 /// </summary>
 /// <param name="context">gate context</param>
 /// <param name="functions">array of gated functions</param>
 /// <typeparam name="T">the return type of the function</typeparam>
 /// <returns>instance of T (default if no applicable action found)</returns>
 public static Task <T> PerformFunction <T>(this IGateContext context, params GatedAsyncFunc <T>[] functions) => SelectFunction(context, functions)();
Пример #17
0
 /// <summary>
 /// Perform a function that is applicable in the current gate context
 /// </summary>
 /// <typeparam name="T">the return type of the function</typeparam>
 /// <param name="context">gate context</param>
 /// <param name="gate">target gate</param>
 /// <param name="function">function delegate</param>
 /// <returns>instance of T (default if no applicable action found)</returns>
 public static Task <T> PerformFunction <T>(this IGateContext context, IGate gate, Func <Task <T> > function) => SelectFunction(context, new GatedAsyncFunc <T>(gate, function))();
Пример #18
0
 /// <summary>
 /// Perform a function that is applicable in the current gate context
 /// </summary>
 /// <typeparam name="T">the return type of the function</typeparam>
 /// <param name="context">gate context</param>
 /// <param name="gate">target gate</param>
 /// <param name="function">function delegate</param>
 /// <returns>instance of T (default if no applicable action found)</returns>
 public static T PerformFunction <T>(this IGateContext context, IGate gate, Func <T> function) => SelectFunction(context, new GatedFunc <T>[] { new GatedFunc <T>(gate, function) })();
Пример #19
0
        public void Select(SelectFunction selectFunction, string fieldName)
        {
            var selectionString = string.Format("{0}({1})", selectFunction.ToString(), fieldName);

            _selectionList.Add(selectionString);
        }
 public void Select(string tableName, string fieldName, SelectFunction selectFunction)
 {
     var selectionString = string.Format("{0}({1})", selectFunction.ToString(), Adapter.Field(tableName, fieldName));
     _selectionList.Add(selectionString);
 }
Пример #21
0
        public void SelectWithFunction <T>(Expression <Func <T, object> > expression, SelectFunction selectFunction, string aliasName, string tableAlias)
        {
            var fieldName = "*";

            if (expression != null)
            {
                fieldName = GetColumnName(GetMemberExpression(expression.Body));
            }

            _builder.Select(tableAlias, fieldName, selectFunction, aliasName);
        }
Пример #22
0
        public void SelectWithFunctionSubQuery <T, TMain>(Expression <Func <T, object> > expression, SelectFunction selectFunction, Expression <Func <TMain, object> > aliasProp, string subAlias)
        {
            var fieldName = "*";

            if (expression != null)
            {
                fieldName = GetColumnName(GetMemberExpression(expression.Body));
            }

            var aliasFieldName = "";

            if (aliasProp != null)
            {
                aliasFieldName = GetColumnName(GetMemberExpression <TMain>(aliasProp.Body));
            }

            _builder.Select(subAlias, fieldName, selectFunction, aliasFieldName);
        }
 internal void SelectWithFunction <TTable>(Expression <Func <TTable, object> > expression, SelectFunction selectFunction, string tableAlias, string columnAlias)
 {
     _lambdaResolverExtension.SelectWithFunction <TTable>(expression.Body, selectFunction, tableAlias, columnAlias);
 }
 public void SelectWithFunction <T>(SelectFunction selectFunction)
 {
     Builder.Select(selectFunction);
 }
        internal void SelectWithFunctionWithoutColumn <TTable>(SelectFunction selectFunction, string tableAlias, string columnAlias)
        {
            var tableName = SqlBuilderFluentHelper.GetTableName <TTable>();

            _sqlQueryBuilder.Select(tableName, null, selectFunction, tableAlias, columnAlias);
        }
        public void Select(string tableName, string fieldName, SelectFunction selectFunction)
        {
            var selectionString = $"{selectFunction}({Adapter.Field(tableName, fieldName)})";

            SelectionList.Add(selectionString);
        }
Пример #27
0
 public void SelectWithFunction <T>(SelectFunction selectFunction, string fieldName = "*")
 {
     _builder.Select(selectFunction, fieldName);
 }
        public void Select(SelectFunction selectFunction)
        {
            var selectionString = $"{selectFunction}(*)";

            SelectionList.Add(selectionString);
        }
        public void SelectWithFunctionSubQuery <T>(Expression <Func <T, object> > expression, SelectFunction selectFunction, string subAlias)
        {
            var fieldName = "*";

            if (expression != null)
            {
                fieldName = GetColumnName(GetMemberExpression(expression.Body));
            }

            _builder.Select(subAlias, fieldName, selectFunction, "");
        }
Пример #30
0
        public void Select(string tableName, string fieldName, SelectFunction selectFunction)
        {
            var selectionString = string.Format("{0}({1})", selectFunction.ToString(), Adapter.Field(tableName, fieldName));

            _selectionList.Add(selectionString);
        }
Пример #31
0
 /// <summary>
 /// Perform a function that is applicable in the current gate context based on the passed predicate.
 /// </summary>
 /// <typeparam name="T">Generic type.</typeparam>
 /// <param name="context">The context.</param>
 /// <param name="conditionalPredicate">The conditional predicate.</param>
 /// <param name="functions">The functions.</param>
 /// <returns>Func to perform, (default if no applicable action found)</returns>
 public static T PerformConditionalFunction <T>(this IGateContext context, Func <bool> conditionalPredicate,
                                                params GatedFunc <T>[] functions) => SelectFunction(context, GatedCode.Modes.Scoped, conditionalPredicate, functions)();