public List <TableHeaders> GetTableHeaders(CMADataContext dataContext, string tableName) { List <TableHeaders> tableHeaders = new List <TableHeaders>(); if (dataContext != null) { foreach (var table in dataContext.Mapping.GetTables()) { if (string.Equals(table.TableName, "dbo." + tableName)) { foreach (var col in table.RowType.DataMembers) { TableHeaders row = new TableHeaders(); row.ColumnName = col.MappedName; row.IsPrimaryKey = col.IsPrimaryKey; string dbType; int length; GetDatabaseType(col.DbType, out dbType, out length); row.Length = length; row.DataType = dbType; row.Required = !col.CanBeNull; tableHeaders.Add(row); } } } } return(tableHeaders); }
/// <summary> /// Constructor: A metadata wrapper for different types of /// unique/redundant primary or composite keyed CSV document classes. /// </summary> /// <param name="data">Data from which to derive a key, if any.</param> /// <param name="sampleColumnTypes">A dictionary of column types in the derived type of Record</param> /// <param name="keyIsUniqueIdentifier">Is the primary or composite key a unique identifier? /// <br>(Sometimes they're not.)</br></param> public BasicRecord( StringMap data , TableHeaders sampleColumnTypes , bool keyIsUniqueIdentifier = true) : base() { try { foreach (KeyValuePair <string, string> record in data) { Add(record.Key, record.Value); } recordKey = new KeyStrings(); // TO DO: Decouple from clientETLProcess (should be providable from FileDataRecords). foreach (KeyValuePair <string, (Type colType, bool isKey)> headerData in sampleColumnTypes.Where((x) => x.Value.isKey == true)) { bool success = data.TryGetValue(headerData.Key, out string dataValue); if (success) { recordKey.Add((dataValue ??= data[headerData.Key], headerData.Key)); } else { Log.WriteException("Bad key assignent or unknown failure in TryGetValue."); } } }catch (WarningException err) { Log.Write("ETLProcess threw Warning: " + err.ToString() + "at BasicRecord constructor."); } this.keyIsUniqueIdentifier = keyIsUniqueIdentifier; //this.headers = keyHeaders; }
/*****Constructors*****/ /// <summary> /// A class to create a DataTable and link it to a DataSet, according to a constraint. /// </summary> /// <param name="source">Each Stringmap in the List of Stringmaps is a line of strings, with a string for a column.</param> /// <param name="sampleColumns">A dictionary of column types from the client-specific implementation classes.</param> /// <param name="constraint">Optional assembly of settings for foreign key constraints for this table, if any.</param> /// <param name="longName">A short name for this table -- if null, will be the name of the record class in the table's rows. /// <br>The List of strings after this is the headers.</br></param> public FileDataRecords( HeaderSource<List<StringMap>, List<string>> source , Dictionary<Type, TableHeaders> sampleColumns , ForeignKeyConstraintElements constraint = null , string longName = null) : base(typeof(TBasicRecord).Name) { columnInfo = sampleColumns[typeof(TBasicRecord)]; unique = SampleBasicRecord.keyIsUniqueIdentifier; List<StringMap> dataList = source.data; // list of dictionaries of data strings, keyed by column strings List<string> headerStrings = source.headers; var src = new Dictionary<KeyStrings, TBasicRecord>(); // TO DO: Analyze for parallelism foreach (StringMap strMap in dataList) { // Add a new Keystrings, record pair to the DataTable. TBasicRecord record = ((IRecord<TBasicRecord>)SampleBasicRecord).Record( strMap , columnInfo , headerStrings); src.Add( record.recordKey, record ); } TableName = $"FilesIn_Table_{ typeof(TBasicRecord).Name}_{ IODirectory.PrepGuid}_{ctr}"; this.longName = longName ?? string.Format( $"FilesIn_Table_{SampleBasicRecord.GetChildType().Name}_{IODirectory.PrepGuid}_{ctr}"); string index = null; if (ctr > 0) { index = string.Format($"_{ctr}"); } this.TableName = string.Format($"{SampleBasicRecord.GetChildType().Name}{index}"); SetColumns(); SetRows(src); constraint.masterSet.Tables.Add(this); LinkTable_FK(constraint); ctr++; // TO DO: Needed or not? }
public TableOptions(string name, TableHeaders headers) { this.Name = name; this.Headers = headers; }