/// <summary> /// Gets a data parameter for this connection type /// </summary> /// <param name="name">The parameters name</param> /// <param name="value">The value of the parameter</param> /// <returns></returns> public IDbDataParameter GetParameter(string name, object value) { if (value != null) { //postgre is the only one that doesnt do enum.getunderlyingtype() when adding a value to a cmd. So I do it here so it more consistent with the other guys Type type = value.GetType(); object converted = value; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { converted = CLRConverter.ConvertToType(value, type.GetGenericArguments()[0]); if (converted != null) { type = converted.GetType(); converted = typeof(Nullable <>).MakeGenericType(new Type[] { type }).GetConstructor(new Type[] { type }).Invoke(new object[] { converted }); } } if (type.IsEnum) { converted = Convert.ChangeType(converted, Enum.GetUnderlyingType(type)); } return(new NpgsqlParameter(name, converted)); } else { return(new NpgsqlParameter(name, value)); } }
private void AddColumn(IDataStore dstore, IQueryRow columns, DBObject t) { Column toAdd = new Column(); toAdd.ColumnLength = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("COLUMN_SIZE"), typeof(string))).Trim(); toAdd.DataType = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("TYPE_NAME"), typeof(string))).Trim(); toAdd.DefaultValue = null; toAdd.IsPrimaryKey = false; toAdd.Name = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("COLUMN_NAME"), typeof(string))).Trim(); t.Columns.Add(toAdd); }