private TableModel CreateTableModel(DataRow tableRow) { TableModel tableModel = new TableModel(); tableModel.Schema = Convert.ToString(tableRow["Schema"]); tableModel.Name = Convert.ToString(tableRow["Name"]); tableModel.Description = Convert.ToString(tableRow["Description"]); // Columns foreach (DataRow row in this._tTableColumns.Select(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[Schema] = '{0}' AND [TableName] = '{1}'", tableModel.Schema, tableModel.Name))) { ColumnModel columnModel = this.CreateColumnModel(row); tableModel.Columns.Add(columnModel); } // Identity foreach (DataRow row in this._tIdentities.Select(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[Schema] = '{0}' AND [TableName] = '{1}'", tableModel.Schema, tableModel.Name))) { IdentityModel identityModel = this.CreateIdentityModel(row); tableModel.Identity = identityModel; } // PrimaryKeys foreach (IGrouping <string, DataRow> row in this._tIndices.Select(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[Schema] = '{0}' AND [TableName] = '{1}' AND [IsPrimaryKey] = 1", tableModel.Schema, tableModel.Name)).GroupBy(p => Convert.ToString(p["IndexName"]))) { PrimaryKeyConstraintModel primaryKeyConstraintModel = this.CreatePrimaryKeyConstraintModel(row.ToArray()); tableModel.Constraints.Add(primaryKeyConstraintModel); } // Indexes foreach (IGrouping <string, DataRow> row in this._tIndices.Select(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[Schema] = '{0}' AND [TableName] = '{1}' AND [IsPrimaryKey] = 0", tableModel.Schema, tableModel.Name)).GroupBy(p => Convert.ToString(p["IndexName"]))) { IndexModel indexModel = this.CreateIndexModel(row.ToArray()); tableModel.Indexes.Add(indexModel); } return(tableModel); }
private IdentityModel CreateIdentityModel(DataRow identityRow) { IdentityModel identityModel = new IdentityModel(); identityModel.ColumnName = Convert.ToString(identityRow["ColumnName"]); identityModel.Seed = Convert.ToInt64(identityRow["Seed"]); identityModel.Increment = Convert.ToInt64(identityRow["Increment"]); return(identityModel); }