title: Access the context inside Up in DbMigration
body: <p>I'm trying to migrate my db based on my data in my current db. I'm having a hard time querying the db to grab information to allow me to do this. My ideal solution would look something like</p>
  
  <pre><code>public partial class Reset: DbMigration
  {
      public override void Up()
      {
          string SqlCmd = "my query";
          if(Execute(SqlCmd) &gt; 5)
          {
              //do this migration
          }
      }
  }
  </code></pre>
  
  <p>So I'm having problem getting data back in the migration. </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Many of you guys have been wondering why I need to do this, so I'll give you guys the nasty details. </p>
  
  <p>So as our project have grown, so did our db migration history. We have over 200 rows in our migration history table. We split the db up and did some maintenance here and there to the point that running all the migrations from scratch with an empty db would result in an error because some tables weren't created yet. Yes its a huge mess and that's why I wanted to clean it up. I ran into this post on <a href="https://stackoverflow.com/questions/11679385/reset-entity-framework-migrations">SO to reset the migrations to a clean slate.</a> I didn't use the accepted answer because the migration mess we have wouldn't allow it to work. So the second highest answer was used. The only problem with this chosen solution was that for every developer in your team, you'd have to point them to the instructions to update their db or have them download the latest one. They're not able to do </p>
  
  <pre><code>update-database 
  </code></pre>
  
  <p>cleanly. So to allow them to update cleanly and make it hassle free for everyone, I'd like to query the migration history table, see if its the mess and if so delete all the history and skip the actual migration, but still populate the migration row in the table.</p>