none
Running Application Business Logic in a Migration to Update the Database RRS feed

  • Question

  • Hi,

    We would like to use our EntityFramework models during a migration to update existing records in the database following schema changes.  We have business logic within our models that needs to run at the time of the migration to correctly update the database.  After doing some research, it doesn't appear that EntityFramework has direct support for what we want to do.  I know that you can execute SQL statements within a migration to alter the database, but that only gets us so far.  Also, the Seed method provided by Configuration.cs doesn't feel like a solution because of when it runs (after all pending migrations have been applied), and the limited nature of what it's designed to do (add/update read-only seed data).

    Hopefully I'm overlooking something here.  How do folks who are using Code-First EntityFramework handle this situation, where you need to modify existing records in the database, and need to use your application logic to do it?  Any and all suggested workarounds are welcomed (i.e. doesn't have to be pretty).

    Thanks,

    Denis


    Thursday, October 29, 2015 3:47 PM

Answers