public ISchemaBuilder CreateMapIndexTable(Type indexType, Action <ICreateTableCommand> table, string collection) { try { var indexName = indexType.Name; var indexTable = TableNameConvention.GetIndexTable(indexType, collection); var createTable = new CreateTableCommand(Prefix(indexTable)); var documentTable = TableNameConvention.GetDocumentTable(collection); // NB: Identity() implies PrimaryKey() createTable .Column <int>("Id", column => column.Identity().NotNull()) .Column <int>("DocumentId") ; table(createTable); Execute(_commandInterpreter.CreateSql(createTable)); CreateForeignKey("FK_" + (collection ?? "") + indexName, indexTable, new[] { "DocumentId" }, documentTable, new[] { "Id" }); AlterTable(indexTable, table => table.CreateIndex($"IDX_FK_{indexTable}", "DocumentId") ); } catch { if (ThrowOnError) { throw; } } return(this); }
public ISchemaBuilder DropReduceIndexTable(Type indexType, string collection = null) { try { var indexTable = TableNameConvention.GetIndexTable(indexType, collection); var documentTable = TableNameConvention.GetDocumentTable(collection); var bridgeTableName = indexTable + "_" + documentTable; if (String.IsNullOrEmpty(Dialect.CascadeConstraintsString)) { DropForeignKey(bridgeTableName, "FK_" + bridgeTableName + "_Id"); DropForeignKey(bridgeTableName, "FK_" + bridgeTableName + "_DocumentId"); } DropTable(bridgeTableName); DropTable(indexTable); } catch { if (ThrowOnError) { throw; } } return(this); }
public ISchemaBuilder AlterIndexTable(Type indexType, Action <IAlterTableCommand> table, string collection) { var indexTable = TableNameConvention.GetIndexTable(indexType, collection); AlterTable(indexTable, table); return(this); }
private static void ResolveTableInfo(SimpleDataDescriptor descriptor, Type type) { var tableAttributes = type.GetCustomAttributes(typeof(TableAttribute), true); if (tableAttributes.Length > 0 && tableAttributes[0] is TableAttribute attribute) { descriptor.Table = TableNameConvention?.Invoke(attribute.Name) ?? attribute.Name; descriptor.Schema = attribute.Schema; } else { descriptor.Table = TableNameConvention?.Invoke(type.GetNonGenericName()) ?? type.GetNonGenericName(); } }
private string GetTableName(ITypeMappingConfiguration configuration) { var tableName = configuration.TableName; if (String.IsNullOrEmpty(tableName)) { tableName = configuration.ElementType.Name; } if (TableNameConvention != null) { tableName = TableNameConvention.FormatName(tableName); } return(tableName); }
public ISchemaBuilder DropMapIndexTable(Type indexType, string collection = null) { try { var indexName = indexType.Name; var indexTable = TableNameConvention.GetIndexTable(indexType, collection); if (String.IsNullOrEmpty(Dialect.CascadeConstraintsString)) { DropForeignKey(indexTable, "FK_" + (collection ?? "") + indexName); } DropTable(indexTable); } catch { if (ThrowOnError) { throw; } } return(this); }
public ISchemaBuilder CreateReduceIndexTable(Type indexType, Action <ICreateTableCommand> table, string collection = null) { try { var indexName = indexType.Name; var indexTable = TableNameConvention.GetIndexTable(indexType, collection); var createTable = new CreateTableCommand(Prefix(indexTable)); var documentTable = TableNameConvention.GetDocumentTable(collection); createTable .Column <int>("Id", column => column.Identity().NotNull()) ; table(createTable); Execute(_commandInterpreter.CreateSql(createTable)); var bridgeTableName = indexTable + "_" + documentTable; CreateTable(bridgeTableName, bridge => bridge .Column <int>(indexName + "Id", column => column.NotNull()) .Column <int>("DocumentId", column => column.NotNull()) ); CreateForeignKey("FK_" + bridgeTableName + "_Id", bridgeTableName, new[] { indexName + "Id" }, indexTable, new[] { "Id" }); CreateForeignKey("FK_" + bridgeTableName + "_DocumentId", bridgeTableName, new[] { "DocumentId" }, documentTable, new[] { "Id" }); } catch { if (ThrowOnError) { throw; } } return(this); }
public void CreateConvention() { convention = new TableNameConvention(); }