Entity Framework Code First Don't Create Table

entity-framework entity-framework-6

Question

I'm using an existing database and I have mapped one of the tables as an entity (as i needed to map a foreign key).

So when it comes to initialising this database I would like EF to ignore this entity since it already exists.

How would I go about doing this?

1
1
6/17/2014 1:27:50 PM

Popular Answer

You should create an empty migration as the first migration with the -IgnoreChanges flag to allow Entity Framework to get a snapshot of the existing database.

So out of the gate use:

Add-Migration InitialMigration -IgnoreChanges

and that will create a blank migration but it will update the Entity Framework metadata allowing the existing tables to exist and not be touched by migrations.

Also to be mentioned that the naming conventions that Entity Framework expects and your database schema may differ. You may need to manually setup the foreign keys using the Fluent API.

3
6/17/2014 1:34:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow