diff --git a/FAuth.Database/FAuthDb.cs b/FAuth.Database/FAuthDb.cs index c6b1b6a..dd7b529 100644 --- a/FAuth.Database/FAuthDb.cs +++ b/FAuth.Database/FAuthDb.cs @@ -9,7 +9,7 @@ namespace FAuth.DataBase public class FAuthDb:DbContext { public FAuthDb(DbContextOptions options) : base(options) { - Database.EnsureCreatedAsync().Wait(); + //Database.EnsureCreatedAsync().Wait(); } protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/FAuth/FAuth.csproj b/FAuth/FAuth.csproj index fdf3358..118afe9 100644 --- a/FAuth/FAuth.csproj +++ b/FAuth/FAuth.csproj @@ -10,6 +10,7 @@ + diff --git a/FAuth/Startup.cs b/FAuth/Startup.cs index 8e05609..9838041 100644 --- a/FAuth/Startup.cs +++ b/FAuth/Startup.cs @@ -39,7 +39,18 @@ namespace FAuth services.AddMsJsonProvider(); //注册数据库 services.AddDbContext(option => { - option.UseSqlServer(Configuration.GetConnectionString("FAuthDb")); + //option.UseSqlServer(this.Configuration.GetValue("Database:FAuthDbSqlServer")); + var dbType = this.Configuration.GetValue("Database:UseDb").ToLower(); + switch(dbType) { + case "mysql": + option.UseMySQL(this.Configuration.GetValue("Database:FAuthDbMySql")); + break; + case "sqlserver": + option.UseSqlServer(this.Configuration.GetValue("Database:FAuthDbSqlServer")); + break; + default: + throw new Exception("Database:UseDb配置错误!只能为mysql或sqlserver"); + } }); services.AddAccountHelper(); //注册Redis diff --git a/FAuth/appsettings.json b/FAuth/appsettings.json index 6793831..b4f4b5e 100644 --- a/FAuth/appsettings.json +++ b/FAuth/appsettings.json @@ -7,8 +7,10 @@ } }, "AllowedHosts": "*", - "ConnectionStrings": { - "FAuthDb": "Server=.\\SQLSERVER2008R2;Database=FAuth;User ID=sa;Password=111" + "Database": { + "UseDb": "sqlserver", + "FAuthDbSqlServer": "Server=.\\SQLSERVER2008R2;Database=FAuth;User ID=sa;Password=111", + "FAuthDbMySql": "server=localhost;user id=root;password=root;persistsecurityinfo=True;database=FAuth;SslMode=none" }, "Redis": { "InstanceName": "",