Ejemplo n.º 1
0
 /// <summary>
 /// Adds a key column to the table from the specified type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="columnName"></param>
 /// <param name="precision"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 public TableBuilder WithColumnFromType <T>(string columnName, int precision, int scale)
 {
     if (columnName == null)
     {
         throw new ArgumentNullException(nameof(columnName));
     }
     Columns[columnName] = new SqlType(DbTypeMapper.GetDbType(typeof(T)), precision, scale);
     return(this);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a key column to the table from the specified type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="keyColumnName"></param>
 /// <param name="isIdentity"></param>
 /// <returns></returns>
 public TableBuilder WithKeyColumnFromType <T>(string keyColumnName, bool isIdentity = false)
 {
     if (keyColumnName == null)
     {
         throw new ArgumentNullException(nameof(keyColumnName));
     }
     Columns[keyColumnName] = new SqlType(DbTypeMapper.GetDbType(typeof(T)), isIdentity);
     KeyColumns.Add(keyColumnName);
     return(this);
 }
Ejemplo n.º 3
0
        public Translator(SourceTable tbl, IDataReader source, IEnumerable <SourceColumn> srcColumns, Converter[] converter)
        {
            if (tbl == null)
            {
                throw new ArgumentNullException("tbl");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (srcColumns == null)
            {
                throw new ArgumentNullException("srcColumns");
            }

            //_tbl = tbl;
            _source          = source;
            _srcColumns      = srcColumns.ToArray();
            _srcColumnsInfos = _srcColumns.Select(
                col => new SourceColumnInfo(DbTypeMapper.GetDbTypeForProperty(col.DestinationProperty.Last().GetType()),
                                            DbTypeMapper.GetDbType(col.DbType),
                                            col.DestinationProperty.Last() is EnumerationProperty,
                                            col.DestinationProperty.First() is CompoundObjectProperty)).ToArray();
            _converter = converter != null?converter.ToDictionary(c => c.Column) : new Dictionary <SourceColumn, Converter>();

            _resultColumnCount = _srcColumns.Length;

            if (typeof(IMigrationInfo).IsAssignableFrom(tbl.DestinationObjectClass.GetDataType()))
            {
                // TODO: That's a bad hack!
                _errorColIdx = _resultColumnCount;
                _resultColumnCount++;
            }
            else
            {
                _errorColIdx = -1;
            }


            foreach (var comp in srcColumns
                     .Where(c => c.DestinationProperty.First() is CompoundObjectProperty)
                     .GroupBy(c => c.DestinationProperty.First()))
            {
                foreach (var col in comp)
                {
                    _compoundObjectSourceColumns[col.Name] = _resultColumnCount;
                }
                _resultColumnCount++;
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <Column> GetTableColumns(TableRef tbl)
        {
            QueryLog.Debug("GetSchema(Columns)");
            var columns = db.GetSchema(OleDbMetaDataCollectionNames.Columns, new string[] { null, null, tbl.Name, null });

            foreach (DataRow col in columns.Rows)
            {
                int  dt   = (int)col["DATA_TYPE"];
                Type type = DataTypes.ContainsKey(dt) ? DataTypes[dt].Type : typeof(string);
                int  size = (int)(col["CHARACTER_MAXIMUM_LENGTH"] as long? ?? 0);
                if (size == 0 && (type == typeof(string) || type == typeof(byte[])))
                {
                    size = int.MaxValue;
                }
                yield return(new Column()
                {
                    Name = (string)col["COLUMN_NAME"],
                    Size = size,
                    IsNullable = (bool)col["IS_NULLABLE"],
                    Type = DbTypeMapper.GetDbType(type)
                });
            }
        }
Ejemplo n.º 5
0
 public static IDictionary <string, SqlType> ToSqlColumns(this IEnumerable <PropertyInfo> properties)
 {
     return(properties.ToDictionary(p => p.Name, p => new SqlType(DbTypeMapper.GetDbType(p.PropertyType))));
 }