1

I am developing an utility that transfers the data from one structure into another data structure which is then stored in a SQl Server database controlled by Entity-Framework.

Each time I change the target database model I am doing the following;

  1. Deleting the data from the target database.
  2. Running "dbcc checkident("table", reseed)" on each table (many tables) to reset the ID values.
  3. Reseeding the Database using "update-database"

After reading the following http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-first.aspx I think I have two options. I don't think I want to roll my own initialiser.

The first option is to use one of the drop create strategies during development , (dropCreateifmodelChanges, or DropCreateAlways) Will the Drop Create process delete the existing target data, and reseed the Identity counter?

The second option is to somehow include the deletion, and the ID reset in the seed function. Can this be done? If so - how?

Is there a better option? Does anyone have any advice?

TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
Grimley
  • 107
  • 10

1 Answers1

1

Me too had a same sort of situation and I have chosen the manual method which you have mentioned.B'cos it gave me more control over the automatic method.

But you can use the DropCreateDatabaseAlways strategy if you like.Yes,it creates fresh database.That means all the PK values will be reseeded.You can use this strategy only when you're developing the app on dev environment.

Sampath
  • 63,341
  • 64
  • 307
  • 441