File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1- using System . Diagnostics ;
1+ using System ;
2+ using System . Configuration ;
3+ using System . Data . Entity . Infrastructure ;
4+ using System . Data . Entity . Migrations ;
5+ using System . Diagnostics ;
6+ using System . Web . Configuration ;
27using System . Web . Http ;
38using System . Web . Mvc ;
9+ using eFormAPI . Web . Infrastructure . Helpers ;
10+ using eFormAPI . Web . Infrastructure . Models . API ;
11+ using eFormAPI . Web . Migrations ;
412
513namespace eFormAPI . Web
614{
@@ -18,6 +26,24 @@ protected void Application_Start()
1826 {
1927 SwaggerConfig . Register ( GlobalConfiguration . Configuration ) ;
2028 }
29+
30+ // Migrations
31+ try
32+ {
33+ var configuration = WebConfigurationManager . OpenWebConfiguration ( "~" ) ;
34+ var section = ( ConnectionStringsSection ) configuration . GetSection ( "connectionStrings" ) ;
35+ var connString = section . ConnectionStrings [ "eFormMainConnection" ] . ConnectionString ;
36+ var migrationConfiguration = new EformMigrationsConfiguration ( connString )
37+ {
38+ TargetDatabase = new DbConnectionInfo ( connString , "System.Data.SqlClient" )
39+ } ;
40+ var migrator = new DbMigrator ( migrationConfiguration ) ;
41+ migrator . Update ( ) ;
42+ }
43+ catch ( Exception exception )
44+ {
45+ throw new Exception ( $ "Error while migrate database: { exception . Message } ") ;
46+ }
2147 }
2248 }
2349}
You can’t perform that action at this time.
0 commit comments