public SqlExtensionParam AddParameter(SqlExtensionParam param)
            {
                var key = param.Name ?? string.Empty;

                if (!NamedParameters.TryGetValue(key, out var list))
                {
                    list = new List <SqlExtensionParam>();
                    NamedParameters.Add(key, list);
                }

                list.Add(param);
                return(param);
            }
Exemple #2
0
        public void AddNamedParameters(object namedParameters, CrudMethod crudMethodType)
        {
            if (namedParameters == null)
            {
                return;
            }

            var ignoreAttribute = new List <Type> {
                typeof(IgnoreAttribute)
            };

            switch (crudMethodType)
            {
            case CrudMethod.Insert:
                ignoreAttribute.Add(typeof(IgnoreOnInsertAttribute));
                break;

            case CrudMethod.Update:
                ignoreAttribute.Add(typeof(IgnoreOnUpdateAttribute));
                break;
            }

            var props = namedParameters.GetType().GetProperties();

            foreach (var p in props)
            {
                var name             = p.Name;
                var customAttributes = p.GetCustomAttributes(true);
                if (customAttributes.Any(x => x is ColumnAttribute))
                {
                    name = ((ColumnAttribute)customAttributes.Single(x => x is ColumnAttribute)).Name;
                }

                if (customAttributes.Any(x => ignoreAttribute.Contains(x.GetType())))
                {
                    continue;
                }

                var value = p.GetValue(namedParameters, null);
                if (DBNull.Value.Equals(value))
                {
                    value = null;
                }

                NamedParameters.Add(new KeyValuePair <string, object>(name, value));
            }
        }
Exemple #3
0
        public AttributeInfo(Type attributeType, params object[] namedParameters)
        {
            var count = namedParameters.Length % 2 == 0 ?
                        namedParameters.Length / 2 : (namedParameters.Length - 1) / 2;

            this.NamedParameters = new List <Tuple <string, string> >(count);
            this.Parameters      = new List <string>(count);
            for (int i = 0; i < count; i += 2)
            {
                if (namedParameters[i] == null)
                {
                    Parameters.Add(namedParameters[i + 1].ToString( ));
                }
                else
                {
                    NamedParameters.Add(new Tuple <string, string>(namedParameters[i].ToString( ), namedParameters[i + 1].ToString( )));
                }
            }
            this.AttributeType = attributeType;
        }
        public QueryParameters(IDbDataParameter[] parameters)
        {
            int i = 0;

            if (parameters != null)
            {
                foreach (IDbDataParameter param in parameters)
                {
                    _positionalParameterNames[i++]  = param.ParameterName;
                    _positionalParameterValues[i++] = param.Value;
                    NamedParameters.Add(param.ParameterName, param.Value);
                }
            }
            else
            {
                _positionalParameterNames  = new string[] { };
                _positionalParameterValues = new object[] { };
                NamedParameters            = new Dictionary <string, object>();
            }
        }
Exemple #5
0
 public QueryParameter Add(string name, object value)
 {
     NamedParameters.Add(name, value);
     return(this);
 }