Is it possible to change relationships between tables in EF6 without losing data? From my research, my understanding is that many-to-many relationships can be configured using the Fluent API in the onModelCreating method.

What wasn't clear was whether I would be able to change a table from a one-to-many relationship to a many-to-many relationship with a junction table.

有帮助吗?

解决方案

There isn't an explicit migration operation to move the data around like that, what you do is:

  1. Alter your model as desired, either through the fluent API, POCO objects or designer.

  2. In the Up method of the generated migration class, use the DbMigration.Sql method to move the data around in beween the generated Create/Add and Drop statements. Yes, this does involve manually writing the required SQL statements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top