问题详情
136 | 清风大侠
如何配置SqlSugar第三方ORM数据库框架
  • XXX.Web项目中引用
<Project Sdk="Microsoft.NET.Sdk.Web">
    <ItemGroup>
        <PackageReference Include="Known.SqlSugar" Version="1.0.3" />
    </ItemGroup>
</Project>
  • Program.cs文件中添加如下代码
builder.Services.AddKnownSqlSugar(config =>
{
    config.DbType = DbType.SqlServer;
    config.ConnectionString = builder.Configuration.GetSection("ConnString").Get<string>();
    config.IsAutoCloseConnection = true;
    config.MoreSettings ??= new ConnMoreSettings();
    config.MoreSettings.IsAutoToUpper = false;
    config.AopEvents ??= new AopEvents();
    config.AopEvents.OnLogExecuting = (sql, pars) =>
    {
        //var param = string.Join(",", pars.Select(p => $"{p.ParameterName}={p.Value}"));
        //Console.WriteLine($"SQL: {sql}");
        //Console.WriteLine($"参数: {param}");
    };
});
回复列表

暂无数据