public static void CreateIndexesForForeignKeys(this Configuration configuration, Func<string, bool> includeTablePredicate) { configuration.BuildMappings(); var tables = (ICollection<Table>) tableMappingsProperty.GetValue(configuration, null); foreach (var table in tables.Where(x => includeTablePredicate(x.Name))) { var columnsOfPk = table.HasPrimaryKey ? table.PrimaryKey.Columns.Select(x => x.Name).ToArray() : new string[0]; foreach (var foreignKey in table.ForeignKeyIterator) { if (table.HasPrimaryKey) { var columnsOfFk = foreignKey.Columns.Select(x => x.Name).ToArray(); var fkHasSameColumnsOfPk = !columnsOfPk.Except(columnsOfFk).Concat(columnsOfFk.Except(columnsOfPk)).Any(); if (fkHasSameColumnsOfPk) { continue; } } var idx = new Index(); idx.AddColumns(foreignKey.Columns); idx.Name = "IX" + foreignKey.Name.Substring(2); idx.Table = table; table.AddIndex(idx); } } }
public static void AddMappings(Configuration configuration, SagaMetadataCollection allSagaMetadata, IEnumerable <Type> types, Func <Type, string> tableNamingConvention = null) { var modelMapper = new SagaModelMapper(allSagaMetadata, types, tableNamingConvention); configuration.AddMapping(modelMapper.Compile()); configuration.BuildMappings(); var mappings = configuration.CreateMappings(Dialect.GetDialect(configuration.Properties)); foreach (var type in modelMapper.childTables) { var table = mappings.GetClass(type.FullName)?.Table; if (table == null) { continue; } foreach (var foreignKey in table.ForeignKeyIterator) { var idx = new Index(); idx.AddColumns(foreignKey.ColumnIterator); idx.Name = "IDX" + foreignKey.Name.Substring(2); idx.Table = table; table.AddIndex(idx); } } }
public static void CreateIndexesForForeignKeys(this Configuration configuration) { configuration.BuildMappings(); var tables = (ICollection <Table>)TableMappingsProperty.GetValue(configuration, null); foreach (var table in tables) { foreach (var foreignKey in table.ForeignKeyIterator) { var idx = new Index(); idx.AddColumns(foreignKey.ColumnIterator); idx.Name = "IX" + foreignKey.Name.Substring(2); idx.Table = table; table.AddIndex(idx); } } }