문제

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