Skip to content

Commit

Permalink
#12 #13 其他解决方案
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Feb 18, 2019
1 parent 72d70fe commit c25262c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Senparc.Web/DbContext/SenparcDbContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using Senparc.CO2NET.Extensions;
using Senparc.CO2NET.RegisterServices;
using Senparc.CO2NET.Utilities;
using Senparc.Core.Config;
using Senparc.Core.Models;
using Senparc.Scf.Core.Config;
using Senparc.Scf.Core.Models;
using System;
using System.Diagnostics;
using System.IO;
Expand All @@ -26,8 +27,9 @@ public SenparcEntities CreateDbContext(string[] args)

var builder = new DbContextOptionsBuilder<SenparcEntities>();

//如果运行 Add-Migration 命令,此处可能无法自动获取到连接字符串
var sqlConnection = SenparcDatabaseConfigs.ClientConnectionString ?? "Server=.\\;Database=SCF;Trusted_Connection=True;integrated security=True;";
//如果运行 Add-Migration 命令,并且获取不到正确的网站根目录,此处可能无法自动获取到连接字符串(上述#13问题),
//也可通过下面已经注释的的提供默认值方式解决(不推荐)
var sqlConnection = SenparcDatabaseConfigs.ClientConnectionString; //?? "Server=.\\;Database=SCF;Trusted_Connection=True;integrated security=True;";
builder.UseSqlServer(sqlConnection, b => b.MigrationsAssembly("Senparc.Web"));
return new SenparcEntities(builder.Options);
}
Expand Down

0 comments on commit c25262c

Please sign in to comment.