Rename Entity
When renaming an entity the entity framework core and Confinity need to know about it. Otherwise the migration throws exceptions like "An item with the same key has already been added. Key: System.Object Item [System.String]" or later the publishing and references do not work.
Follow these steps to prevent any issues. In this example the entity A is renamed to B:
- Create a
IPersistenceConfiguration<A>(if not existing) and add abuilder.ToTable("B") - Create a migration. You should see the rename of the table A to B.
- Remove
builder.ToTable("B"). - Rename the entity
AtoB - Create a migration to ensure nothing else changed. The migration should be empty.
- Update the reference checker by adding this SQL:
- Up method:
migrationBuilder.Sql(@" update ""ConfinityEntityReference"" set ""DependentEntityName"" = 'B' where ""DependentEntityName"" = 'A';"); // A and B must be the fully qualified name of this type. - Down method:
migrationBuilder.Sql(@" update ""ConfinityEntityReference"" set ""DependentEntityName"" = 'A' where ""DependentEntityName"" = 'B';");
- Up method:
- Update the replication by adding the following SQL:
- Up method:
migrationBuilder.Sql(@" // @Todo "); - Down method:
// @Todo - Omitting this step causes pending replications to be ignored or will fail.
- Up method: