private void GetColumns <T>(ref IDTSConnectionManagerFlatFile100 manager, EntityTypeConfiguration <T> map) where T : class { foreach (object column in manager.Columns) { manager.Columns.Remove(column); } Type type = typeof(T); T instance = (T)Activator.CreateInstance(type); IEnumerable <Tuple <string, string, int?, int?> > columnInfo = map.GetColumnInfo() .OrderBy(o => o.Item3); Dictionary <string, int> numberLengths = new Dictionary <string, int> { { "LOGRECNO", 7 }, { "AREALAND", 14 }, { "AREAWATR", 14 }, { "POP100", 9 }, { "HU100", 9 } }; foreach (Tuple <string, string, int?, int?> column in columnInfo) { //Console.WriteLine(column); int?columnWidth = numberLengths.ContainsKey(column.Item1) ? numberLengths[column.Item1] : column.Item4; if (!columnWidth.HasValue) { throw new ArgumentException($"Invalid Column width on {column.Item1}"); } dynamic ffColumnObject = manager.Columns.Add(); IDTSConnectionManagerFlatFileColumn100 ffColumn = (IDTSConnectionManagerFlatFileColumn100)ffColumnObject; ffColumn.DataType = column.Item2.Equals("NVARCHAR") ? DataType.DT_STR : DataType.DT_I4; ffColumn.ColumnType = "FixedWidth"; ffColumn.ColumnWidth = columnWidth.Value; ffColumn.MaximumWidth = ffColumn.ColumnWidth; IDTSName100 columnName = ffColumnObject as IDTSName100; if (columnName != null) { columnName.Name = column.Item1; columnName.Description = instance.GetName(column.Item1); } } dynamic ffTerminatingColumnObject = manager.Columns.Add(); IDTSConnectionManagerFlatFileColumn100 ffTerminatingColumn = (IDTSConnectionManagerFlatFileColumn100)ffTerminatingColumnObject; ffTerminatingColumn.DataType = DataType.DT_STR; ffTerminatingColumn.ColumnWidth = 1; ffTerminatingColumn.MaximumWidth = 1; IDTSName100 terminatingColumnName = ffTerminatingColumnObject as IDTSName100; if (terminatingColumnName != null) { terminatingColumnName.Name = "TERMINATOR"; terminatingColumnName.Description = "A single space terminating column to ensure all record rows are matching lengths"; } }