1

Background:

I'm developing an application with Entity Framework Code First and have been using my POCO Model to describe the database schema as much as I can. However there are a few cases where only the migrations API supports what you want (such as adding an index). I didn't want to start adding migrations until later, it's much faster just to recreate the database at this point, however it seemed like the only option.

So I thought I'd see if I could see if migrations would work. I planned on using them eventually and I was hoping I'd just be able to adjust the Initial migration or regenerate it as I went, until it was time to make real migrations. However I had no real luck with this approach either. It seems like code migrations for entity framework are fundamentally flawed in that they force the schema to be stored (serialized) as part of the migration.

For me it meant that there was no possible way to adjust the migration as I had no way to update the Target property (which is essentially a serialized version of my model). I also can't regenerate the migration because there is no way to express the indices separately. Part of the problem is that the way migrations work forces them to be made in a serial fashion, which is terrible when I want to update past migrations or there are multiple developers.

I've therefore chosen to just use context.Database.ExecuteSqlCommand to add the indices however I want to figure out if this limitation in migrations is going to change in the future or if I can work around it.

Question:

Is there any way to update the IMigrationMetadata for an existing migration and is there a way to have a migration that doesn't need the metadata found in the Target field?

Daniel Little
  • 16,975
  • 12
  • 69
  • 93
  • possible duplicate of [Add index with entity framework code first (CTP5)](http://stackoverflow.com/questions/4995642/add-index-with-entity-framework-code-first-ctp5) – undefined Jan 22 '13 at 05:20
  • Yeah I mentioned indices in my question; however I'm actually asking about migrations not a solution to the index problem. – Daniel Little Jan 22 '13 at 05:34
  • Comments of the accepted answer in @Luke's link actually mention migrations: `@ChrisMoschini: If you're doing this in a migration, there appears to be a function called [context.Database.]CreateIndex -- we don't need to write any raw SQL. – Mark`. – Mathieu Guindon Jan 22 '13 at 05:49
  • @retailcoder I'm not doing that in a migration – Daniel Little Jan 22 '13 at 06:00

0 Answers0