
// namespaces...
namespace EntityFirst.Module.Migrations
{
    using EntityFirst.Module.BusinessObjects;
    using System;
    using System.Data.Entity.Migrations;
    using System.IO;
    using System.Linq;
    using System.Threading;

    // internal classes...
    internal sealed class Configuration : DbMigrationsConfiguration<EntityFirst.Module.BusinessObjects.EntityFirstDbContext>
    {
        // public constructors...
        public Configuration()
        {
            TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo("ConnectionString");
            AutomaticMigrationsEnabled = true;
            //AutomaticMigrationDataLossAllowed = true;
        }
        // protected methods...
        protected override void Seed(EntityFirst.Module.BusinessObjects.EntityFirstDbContext context)
        {
            //string line;

            var fileName = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "bin", "script.sql");
            var file = new System.IO.StreamReader(fileName);

            var wholeScript = file.ReadToEnd();
            context.Database.ExecuteSqlCommand(wholeScript);

            /*
            while ((line = file.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line) && !line.Equals("GO")) { 
                    context.Database.ExecuteSqlCommand(line);
                    Thread.Sleep(10);
                }
            }
             */

            file.Close();
        }
    }
}
