引入mysql包。修改配置
This commit is contained in:
parent
dad6ae3362
commit
d4ed14d313
|
@ -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) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.19" />
|
||||
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.19" />
|
||||
<PackageReference Include="NLog" Version="4.7.0" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.2" />
|
||||
|
|
|
@ -39,7 +39,18 @@ namespace FAuth
|
|||
services.AddMsJsonProvider();
|
||||
//注册数据库
|
||||
services.AddDbContext<FAuthDb>(option => {
|
||||
option.UseSqlServer(Configuration.GetConnectionString("FAuthDb"));
|
||||
//option.UseSqlServer(this.Configuration.GetValue<string>("Database:FAuthDbSqlServer"));
|
||||
var dbType = this.Configuration.GetValue<string>("Database:UseDb").ToLower();
|
||||
switch(dbType) {
|
||||
case "mysql":
|
||||
option.UseMySQL(this.Configuration.GetValue<string>("Database:FAuthDbMySql"));
|
||||
break;
|
||||
case "sqlserver":
|
||||
option.UseSqlServer(this.Configuration.GetValue<string>("Database:FAuthDbSqlServer"));
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Database:UseDbÅäÖôíÎó£¡Ö»ÄÜΪmysql»òsqlserver");
|
||||
}
|
||||
});
|
||||
services.AddAccountHelper();
|
||||
//注册Redis
|
||||
|
|
|
@ -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": "",
|
||||
|
|
Loading…
Reference in New Issue
Block a user