How to ignore a table/class in EF 4.3 migrations

前端 未结 2 1673
醉酒成梦
醉酒成梦 2020-12-08 17:44

I\'m testing with EF 4.3 (beta)

I have some new classes which should generate db tables and columns.

From a old project i have some old tables in my schema,

相关标签:
2条回答
  • 2020-12-08 18:05

    The correct workflow in this case is creating first migration prior to adding changes (new classes), than adding new classes and after that creating new migration where you will have only new tables.

    If you didn't use migrations so far the framework will generate migrations for all tables you have in the project because it believes you are creating initial migration. Once you have migration generated you can modify its source file and remove CreateTable code for old classes from Up method. The problem is you will probably have to do this in any subsequent migration.

    Edit: I wrote a walkthrough for adding migrations to existing project with EF 4.3.1

    0 讨论(0)
  • 2020-12-08 18:18

    With EF 4.3.1 released there is built in support for this scenario. When adding classes that are mapped to existing tables in the database, use the -IgnoreChanges switch to Add-Migration.

    This will generate an empty migration, with an updated meta-data signature that contains the newly added classes.

    Usually this is done when starting using EF Migrations, hence the "InitialMigration" name:

    Add-Migration InitialMigration –IgnoreChanges
    
    0 讨论(0)
提交回复
热议问题