Skip to content

Commit 081cf7c

Browse files
author
Leonid
committed
added migrations
1 parent f962d53 commit 081cf7c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

eFormAPI/eFormAPI/Global.asax.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
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;
27
using System.Web.Http;
38
using System.Web.Mvc;
9+
using eFormAPI.Web.Infrastructure.Helpers;
10+
using eFormAPI.Web.Infrastructure.Models.API;
11+
using eFormAPI.Web.Migrations;
412

513
namespace 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
}

0 commit comments

Comments
 (0)