public void AddValueParameters(IQueryParameter input)
        {
            var inputProperties = input.GetType().GetProperties().ToArray();

            if (Parameters == null)
            {
                Parameters = new Dictionary <string, object>();
            }

            foreach (var propertyInfo in _propertyInfos)
            {
                var inputPro = inputProperties.FirstOrDefault(i => string.Equals(i.Name, propertyInfo.Name, StringComparison.CurrentCultureIgnoreCase));

                if (inputPro == null)
                {
                    continue;
                }

                var value = inputPro.GetValue(input, null);

                var name = propertyInfo.Name.ToLower();

                Parameters.Add(name, value);
            }
        }
        public void Analyze(IQueryParameter input)
        {
            var columns =
                input.GetType().GetProperties()
                .Where(i => !SqlBuilderHelper.ShouldIgnore(i, IgnoreTypes));

            Columns = string.Join(
                ",\r\n",
                columns.Select(i => $@"{ParentTable}.[{i.Name}] = @{i.Name.ToLower()}")
                );
        }
Exemple #3
0
        public void Add(string key, IQueryParameter parameter)
        {
            if (!parameter.IsUnique && this.Parameters.Any(
                    e => e.Key == key &&
                    e.Value.GetType() == parameter.GetType()))
            {
                throw new QueryBuilderException(
                          $"Key-Parameter association have to be unique");
            }

            this.Parameters.Add(new KeyValuePair <string, IQueryParameter>(key, parameter));
        }
Exemple #4
0
        public void AddValueParameters(IQueryParameter input)
        {
            var inputProperties = input.GetType().GetProperties().ToArray();

            if (Parameters == null)
            {
                Parameters = new Dictionary <string, object>();
            }

            foreach (var propertyInfo in _propertyInfos)
            {
                var inputPro = inputProperties.FirstOrDefault(i => string.Equals(i.Name, propertyInfo.Name, StringComparison.CurrentCultureIgnoreCase));

                if (inputPro == null)
                {
                    continue;
                }

                var value = inputPro.GetValue(input, null);

                if (value == null)
                {
                    var toremove = _columns.FirstOrDefault(i => string.Equals(i.Name, inputPro.Name, StringComparison.CurrentCultureIgnoreCase));

                    if (toremove != null)
                    {
                        _columns.Remove(toremove);
                    }

                    continue;
                }

                var name = propertyInfo.Name.ToLower();

                Parameters.Add(name, value);
            }

            _values = string.Join(",", Parameters.Select(i => $"@{i.Key.ToLower()}"));
        }