SqlSugar扩展

<PackageReference Include="SqlSugarCore" Version="5.1.4.153-preview08" />
using SlopeRadar.WebApi.Dto;
using SqlSugar;

public static class SqlSugarExtensions
{
    public static void AddCustomSqlSugarClient(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddSingleton<ISqlSugarClient>(new SqlSugarScope(new ConnectionConfig
        {
            ConnectionString = configuration.GetValue<string>("SqlSugar:ConnectionString"),
            DbType = configuration.GetValue<SqlSugar.DbType>("SqlSugar:DbType"),
            IsAutoCloseConnection = true
        }));
    }

    public static IApplicationBuilder UseInitDb(this IApplicationBuilder app)
    {
        using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
        {
            var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
            var configuration = serviceScope.ServiceProvider.GetRequiredService<IConfiguration>();


            #region Framework

            db.CodeFirst.InitTables(typeof(RadarData));


            #endregion


        }

        return app;
    }

}

Sqlite

"SqlSugar": {
  "ConnectionString": "DataSource=SlopeRadar.db", //数据库连接字符串
  "DbType": "Sqlite", //数据库类型
},

MySql

"SqlSugar": {
  "ConnectionString": "Server=127.0.0.1;Port=3306;Database=gpsnat;Uid=root;Pwd=pwd;SslMode=none;",
  "DbType": "MySql",
},

SqlServer

"SqlSugar": {
  "ConnectionString": "server=127.0.0.1;uid=sa;pwd=pwd;database=db", //数据库连接字符串
  "DbType": "SqlServer", //数据库类型
},

QuestDB

"SqlSugar": {
  "ConnectionString": "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;", //数据库连接字符串
  "DbType": "QuestDB", //数据库类型
},