Esempio n. 1
0
        /// <summary>
        /// Adds parameters to a QueryBuilder in order to produce WHERE statements
        /// </summary>
        /// <param name="queryBuilder"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        private QueryBuilder.QueryBuilder AddParameters(QueryBuilder.QueryBuilder queryBuilder, Dictionary <string, object> parameters)
        {
            if (queryBuilder == null)
            {
                throw new ArgumentNullException(nameof(queryBuilder));
            }
            if (parameters == null || parameters.Count == 0)
            {
                return(queryBuilder);
            }

            var paramNum = 0;

            foreach (var parameter in parameters)
            {
                if (paramNum == 0)
                {
                    queryBuilder.Where(new Eq($"t.{parameter.Key}", $"@{parameter.Key}"));
                }
                else
                {
                    queryBuilder.AndWhere(new Eq($"t.{parameter.Key}", $"@{parameter.Key}"));
                }
                paramNum++;
            }

            return(queryBuilder);
        }
Esempio n. 2
0
 public QueryBuilder NestedFrom(QueryBuilder nestedQuery, string Alias = "t")
 {
     expressions.Add(new From(nestedQuery, Alias));
     return(this);
 }