protected IEnumerable <Column> GetColumnDetails(bool getIndexDetails) { EnumerableRowCollection <DataRow> indexColumns = null; if (getIndexDetails) { indexColumns = _connection.GetSchema("IndexColumns").AsEnumerable() .OrderBy(row => row.Field <string>(4)) //Schema .ThenBy(row => row.Field <string>(5)) //Table .ThenBy(row => row.Field <int>(7)); //Ordinal } return(_connection.GetSchema("Columns").AsEnumerable() .Select(row => { Column column = null; var schema = row.Field <string>(1); var table = row.Field <string>(2); var name = row.Field <string>(3); if (getIndexDetails && indexColumns != null) { DataRow indexRow = indexColumns.FirstOrDefault(r => schema.Equals(r.Field <string>(4)) && table.Equals(r.Field <string>(5)) && name.Equals(r.Field <string>(6))); if (indexRow != null) { column = new IndexedColumn { IndexKind = indexRow.Field <byte>(8) == 36 ? IndexKind.PrimaryKey : IndexKind.Unique }; } } if (column == null) { column = new Column(); } column.Schema = schema; column.Table = table; column.Name = name; column.Ordinal = row.Field <int>(4); column.IsNullable = row.Field <string>(6).Equals("YES", StringComparison.OrdinalIgnoreCase); column.Type = GetDataColumnType(row.Field <string>(7)); column.DbType = row.Field <string>(7); return column; }) .OrderBy(c => c.Schema).ThenBy(c => c.Table).ThenBy(c => c.Ordinal)); }
protected IEnumerable<Column> GetColumnDetails(bool getIndexDetails) { EnumerableRowCollection<DataRow> indexColumns = null; if (getIndexDetails) { indexColumns = _connection.GetSchema("IndexColumns").AsEnumerable() .OrderBy(row => row.Field<string>(4)) //Schema .ThenBy(row => row.Field<string>(5)) //Table .ThenBy(row => row.Field<int>(7)); //Ordinal } return _connection.GetSchema("Columns").AsEnumerable() .Select(row => { Column column = null; var schema = row.Field<string>(1); var table = row.Field<string>(2); var name = row.Field<string>(3); if (getIndexDetails && indexColumns != null) { DataRow indexRow = indexColumns.FirstOrDefault(r => schema.Equals(r.Field<string>(4)) && table.Equals(r.Field<string>(5)) && name.Equals(r.Field<string>(6))); if (indexRow != null) { column = new IndexedColumn { IndexKind = indexRow.Field<byte>(8) == 36 ? IndexKind.PrimaryKey : IndexKind.Unique }; } } if (column == null) column = new Column(); column.Schema = schema; column.Table = table; column.Name = name; column.Ordinal = row.Field<int>(4); column.IsNullable = row.Field<string>(6).Equals("YES", StringComparison.OrdinalIgnoreCase); column.Type = GetDataColumnType(row.Field<string>(7)); column.DbType = row.Field<string>(7); return column; }) .OrderBy(c => c.Schema).ThenBy(c => c.Table).ThenBy(c => c.Ordinal); }