From d4ed14d313565a7ff5a9d4ee5aeacdbfa96bc4eb Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Wed, 22 Apr 2020 20:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5mysql=E5=8C=85=E3=80=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FAuth.Database/FAuthDb.cs | 2 +- FAuth/FAuth.csproj | 1 + FAuth/Startup.cs | 13 ++++++++++++- FAuth/appsettings.json | 6 ++++-- 4 files changed, 18 insertions(+), 4 deletions(-) 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": "",