2

I am using Entity Framework 5.0 and have implemented custom migrations.

One thing that I'd like to do is perform some calculation and clean-up jobs after a specific migration is completed. I know that the Seed() method is used for post-migration data manipulation, but it is run with every migration. I want this to only run once after a specific migration is complete.

I would do it inside of the custom migration itself, but the processes require that I pull result sets and perform calculations on them, etc. and I'd like to do this in C# if possible (to utilize our job processing system).

What is the best way to run post-migration processing code for a specific migration?

4

1 に答える 1

1

__MigrationHistory テーブルを調べることで、特定の移行をターゲットにできると思います。しかし、ある時点で移行を再スキャフォールディングする必要があるかもしれないので、それは少し壊れやすいと思います。他の基準に基づいてクリーンアップをトリガーしたいと思います。

データが「汚れている」ことを検出する方法はありますか? その後、必要に応じてクリーンアップをトリガーできます。それが不可能な場合は、データベースにテーブルを作成して、クリーンアップが必要な時期を示すフラグを保持できます。Up() メソッドでフラグを設定し、移行の Down() メソッドでフラグを削除できます。次に、Seed() メソッドでフラグを確認し、クリーンアップをトリガーできます。

これらはEntity Frameworkの移行の良いヒントだと思います

于 2013-08-23T09:05:11.697 に答える