Search code examples
c#entity-frameworkdeploymententity-framework-migrationswebdeploy

File Deploy set database initaliser


I have a c# MVC, entity framework web application and I've been using the web deploy method to move my application from dev to staging to live. Works great.

Our systems team are looking to role out a new server (cluster) and due to permission problems the web deploy method no longer works.

I can do a file deploy and doing some testing this runs through the migrations on launch but doesn't execute the seed command. The web deploy seems to do some extra stuff to the web config that the file one doesn't do.

I'm thinking that the only way to get this working is to do a web deploy - perhaps locally and then copy those files to the live server.

Any other ideas?


Solution

  • In the configuration file I added in.

    public void RunSeed(IE11EnterpriseConfig.Services.DBConn db)
            {
                Seed(db);
            }
    

    Then in Global.asax.cs I added in. (from this question How to run Seed() method of Configuration class of migrations)

    using (var conn = new Services.DBConn())
                {
    
                    var configuration = new Configuration();
                    configuration.RunSeed(conn);
    
                }
    

    Thus an app startup it runs the seed. Bit hacky but they you go.