public static TableData CreateTableDataFromType(Type type) { var tableName = GetTableName(type); var tableCreationData = new TableData() { TableName = tableName, SourceType = type }; var columnCreationDatas = type .GetBasePropertiesFirst() .Where(z => z.GetMethod?.IsStatic != true) .Select(prop => ColumnDataFactory.GetInfo(tableCreationData, prop)) .WhereNotNull() .OrderBy(z => GetColumnOrder(z)) .ToList(); tableCreationData.ColumnCreationData.AddRange(columnCreationDatas); tableCreationData.BuildMultiForeignKeys(); return(tableCreationData); }
public string GetMatchingPrimaryKey() { if (PrimaryType is null) { return(string.Empty); } /* * This is turning out to be difficult. What is unfortunate is that we have no "good" way to get the primary * key information for this type. At this stage we don't have enough processed to be able to query the model * for the primary key(s) of this type. We can basically do an ad-hoc query here manually to come up with * the primary key. Unfortunately, we then have primary-key detection logic in two places, here, and also * in the column data factory that does primary key detection as well. */ /* * Also, this method is trying to allow us to link two types together without specifying the primary key. * So, this really only works when there is a single primary key and that primary key has the same type * as this foreign key column. * So, we should be able to loop through all properties, select the Single that is a primary key, check the * data type against this column, and if we still have a match then that is our primary key we want to use. */ var properties = PrimaryType.GetProperties() .Select(prop => new { Property = prop, PrimaryKeyInfo = ColumnDataFactory .GetPrimaryKeyInfo(prop), ColumnName = ColumnDataFactory.GetColumnName(prop) }) .Where(z => z.PrimaryKeyInfo != null && z.PrimaryKeyInfo.IsPrimaryKey) .ToList(); return(properties.Count switch { 0 => String.Empty, 1 => properties[0].ColumnName.Name, _ => String.Empty });
private static ColumnData[] BuildColumnData() { ColumnData[] columnData = new ColumnData[_columnTable.Length]; for (int i = 0; i < _columnTable.Length; ++i) { columnData[i] = _columnTable[i].Item4 != null ? _columnTable[i].Item4() : ColumnDataFactory.Create(_columnTable[i].Item2); } return(columnData); }