Erik Z
Erik Z

Reputation: 4770

EF Code first and initialize multiple contexts

I'm trying out Code First. I've two seperate contexts using the same database.

My problem is how to use the databaseinitializers.

If I use a initializer that drops the database, it only works for the first context. Then I initialize the secont context, and that initializer delets the tables creatde by the first initializer.

Any advices who to solve this?

Upvotes: 3

Views: 1135

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364259

In case of code first you should not have two different context types for the same database. You should have only one - your use case is not expected in code first scenario.

To solve your problem you must simply use initializer only for one context type and make sure that it is always used first.

Upvotes: 2

Related Questions