private static void UpdateDeclaredIndexes(SqlTable table) { var properties = table.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(pi => (typeof(Index).IsAssignableFrom(pi.PropertyType) || typeof(UniqueConstraint).IsAssignableFrom(pi.PropertyType)) && !pi.GetIndexParameters().Any()); foreach (var property in properties) { var index = (IndexBase)property.GetValue(table); if (!property.Name.StartsWith('_')) { index.Name = property.Name; } index.SqlTable = table; var registeredIdexes = index.SqlColumns.OfType <ColumnAndOrderRegistration>().ToList(); // TODO ? foreach (var cr in registeredIdexes) { index.SqlColumns.Remove(cr); index.SqlColumns.Add(new ColumnAndOrder(table.Columns[cr.ColumnName], cr.Order)); } } }
private static void AddDeclaredColumns(SqlTable table) { var properties = table.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(pi => typeof(SqlColumn).IsAssignableFrom(pi.PropertyType) && !pi.GetIndexParameters().Any()); foreach (var property in properties) { var column = (SqlColumn)property.GetValue(table); column.Name = property.Name; column.Table = table; } }
private static void UpdateDeclaredCustomProperties(SqlTable table) { var properties = table.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(pi => typeof(SqlTableCustomProperty).IsAssignableFrom(pi.PropertyType) && !pi.GetIndexParameters().Any()); // TODO ? foreach (var property in properties) { var customProperty = (SqlTableCustomProperty)property.GetValue(table); customProperty.SqlTable = table; } }
private static void AddDeclaredForeignKeys(SqlTable table) { var properties = table.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(pi => typeof(ForeignKey).IsAssignableFrom(pi.PropertyType) && !pi.GetIndexParameters().Any()); foreach (var property in properties) { var fk = (ForeignKey)property.GetValue(table); if (!property.Name.StartsWith('_')) { fk.Name = property.Name; } fk.SqlTable = table; } }