# Entity Framework 6 # ## Notes ## public class HelpSeederOperation : MigrationOperation { /// /// List of Help Entries to process /// public List HelpEntries { get; private set; } public HelpSeederOperation(List helpEntries) : base(null) { HelpEntries = helpEntries; } // Clean out the database public override bool IsDestructiveChange { get { return false; } } } public static class SeederExtensions { public static void AddHelpEntries(this DbMigration migration, List helpEntries) { ((IDbMigration)migration).AddOperation(new HelpSeederOperation(helpEntries)); } } public class HomeGrownHelpSeedingSqlServerMigrationSqlGenerator : SqlServerMigrationSqlGenerator { protected override void Generate(MigrationOperation migrationOperation) { var operation = migrationOperation as HelpSeederOperation; if (operation != null) { // Create the custom SQL based on the List of HelpEntry items sent through. var sb = new StringBuilder(); sb.AppendLine("SET IDENTITY_INSERT [Xact_HelpEntry] ON"); operation.HelpEntries.ForEach( x => { sb.AppendLine( string.Format( "INSERT INTO [Xact_HelpEntry] VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}) ", x.Id, x.ParentFK, x.Enabled, x.Key, x.KeyLowered, x.ResourceFilter, x.ResourceKey, x.CategoryFK, x.Description, 1, 0)); }); Statement(sb.ToString()); } } ## References * http://romiller.com/2013/02/27/ef6-writing-your-own-code-first-migration-operations/