3

I've created a new class, and EF will create a migration code when I'll do add-migration in Package Manager Console. Since this table is a classifier, I want to populate it with data and include this data in migration. I cannot use Seed method, since i'll be using my generated migration on production database later on.

Where should I hardcode the values for this table? I can edit the generated migration cs file, but this seems an inelegant solution. Could you recommend more proper place to define the data?

1 Answer 1

3

I think if you're goal is to populate your table for development/testing, there's no reason you shouldn't do you data seeding via the Seed method. You could always wrap the seed code for this table with an if block that checks your connection string values.

Edit: If you plan to populate your table in your production database with the same data, it would certainly make sense to do so in the Up method of that specific migration that creates the table.

Sign up to request clarification or add additional context in comments.

3 Comments

Not exactly - my goal is to populate the table for production also. If it was for dev/testing only I would put the data in Seed method.
In that case, you would be better off adding your hard-coded data within your migration class.
In the end, i've added the data inside the generated migration script- it seems there are no significantly better ways to do this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.