0
votes

Working on a new feature using EF6 with code first migrations made my development super awesome. Now that I'm passed the prototype phase, I need to integrate this process with my larger code base & change control processes.

Migrations are awesome, and I'd love to use them if I was in a different situation, but the database code is currently executed in a separate change control process when I release code. Additionally, the schema is version controlled using a database project from Visual Studio 2010.

Is there a way to mock the __migrationHistory table so when I deploy, I will not get any errors from EF6? Additionally, is there a way to script the output of a fluent migration to a file output for a DBA to execute? I see that I could manually create row entries, but I'm unsure what is stored in the Model binary field and if it might just be the actual T-SQL underneath.

1
I did see that there is an option to write the output of Update-Database to a file via coding.abel.nu/2012/03/ef-migrations-command-reference - Dennis P

1 Answers

0
votes

A few notes for future people looking to do this.

You can write the EF6 migrations to a SQL file using Update-Database -Script option.

This helps when you are doing SQL updates separately than code.

Secondly, if you mark your fields as [DataMember(IsRequired = false)] and add code in the OnModelCreating override function to ignore it, you can continue using EF6 without the database completely in sync:

public class DotNetObject
{
   [DataMember(IsRequired = false)]
   public int ColumnName { get; set; }
}

 protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
 {
                modelBuilder.Entity<DotNetObject>().Ignore(sc => sc.ColumnName);
    modelBuilder.Entity<DotNetObject>().Ignore(sc => sc.ColumnName);
 }