第一种

appsettings.json

{

  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;database=typecho;uid=root;pwd=woshishui;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

ConfigureServices

 services.AddDbContext<typechoContext>(options=>options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));


第二种

ConfigureServices

      // other service configurations go here
            // replace "YourDbContext" with the class name of your DbContext
services.AddDbContextPool<typechoContext>(options => options
            //     // replace with your connection string          .UseMySql("Server=localhost;Database=typecho;User=root;Password=woshishui;", mySqlOptions => mySqlOptions
            //         // replace with your Server Version and Type
    .ServerVersion(new ServerVersion(new Version(8, 0, 19), ServerType.MySql))
            //     ));

相关文章:

  • 2021-05-07
  • 2021-12-19
  • 2021-06-20
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-16
  • 2021-12-30
  • 2021-10-06
  • 2021-05-17
  • 2022-12-23
  • 2021-12-09
  • 2021-04-25
相关资源
相似解决方案