diff --git a/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs b/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs index 585f2f7..7b05f80 100644 --- a/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs +++ b/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs @@ -24,6 +24,28 @@ public class NPinFrameworkSqlSugarCoreModule : AbpModule var configuration = service.GetConfiguration(); Configure(configuration.GetSection("DbConnOptions")); + if (Enum.TryParse( + configuration.GetSection(nameof(DbConnOptions)).GetSection(nameof(DbConnOptions.DbType)).Value, + out var dbType)) + { + Configure(opt => + { + switch (dbType) + { + case DbType.PostgreSQL: + case DbType.MySql: + opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsString; + break; + case DbType.Oracle: + opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary; + break; + default: + opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAtEnd; + break; + } + }); + } + // 开放 sqlSugarClient service.TryAddScoped(); // 不开放 sqlSugarClient @@ -45,23 +67,6 @@ public class NPinFrameworkSqlSugarCoreModule : AbpModule var service = context.ServiceProvider; var options = service.GetRequiredService>().Value; - Configure(opt => - { - switch (options.DbType) - { - case DbType.PostgreSQL: - case DbType.MySql: - opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsString; - break; - case DbType.Oracle: - opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary; - break; - default: - opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAtEnd; - break; - } - }); - var logger = service.GetRequiredService>(); StringBuilder sb = new StringBuilder(); diff --git a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs index 2a95709..72fdff5 100644 --- a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs +++ b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs @@ -90,11 +90,6 @@ public class SqlSugarDbConnectionCreator : ISqlSugarDbConnectionCreator, ITransi { EntityService = (c, p) => { - if (new NullabilityInfoContext().Create(c).WriteState is NullabilityState.Nullable) - { - p.IsNullable = true; - } - EntityService(c, p); }, EntityNameService = (t, e) => diff --git a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbContext.cs b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbContext.cs index ee79f01..df79538 100644 --- a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbContext.cs +++ b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbContext.cs @@ -219,28 +219,27 @@ public class SqlSugarDbContext : ISqlSugarDbContext protected virtual void OnLogExecuting(string sql, SugarParameter[] pars) { - if (Options.EnabledSqlLog) - { - StringBuilder sb = new StringBuilder(); - sb.AppendLine(); - sb.AppendLine("==========NPin-SQL=========="); - sb.AppendLine(UtilMethods.GetSqlString(DbType.SqlServer, sql, pars)); - sb.AppendLine("============================"); - Logger.CreateLogger().LogDebug(sb.ToString()); - } } protected virtual void OnLogExecuted(string sql, SugarParameter[] pars) { if (Options.EnabledSqlLog) { - var sqllog = $"=========NPin-SQL耗时{SqlSugarClient.Ado.SqlExecutionTime.TotalMilliseconds}毫秒====="; - Logger.CreateLogger().LogDebug(sqllog); + var log = Logger.CreateLogger(); + + var sb = new StringBuilder(); + sb.AppendLine(); + sb.AppendLine("==========NPin-SQL=========="); + sb.AppendLine(UtilMethods.GetNativeSql(sql, pars)); + sb.AppendLine($"Count: {SqlSugarClient.Ado.SqlExecuteCount}"); + sb.AppendLine($"耗时 {SqlSugarClient.Ado.SqlExecutionTime.TotalMilliseconds} 毫秒"); + log.LogDebug(sb.ToString()); } } /// /// 实体配置 + /// 自动 Nullable /// 自动主键 /// 自动Ignore关联配置(导航) /// 开启下划线 @@ -249,6 +248,12 @@ public class SqlSugarDbContext : ISqlSugarDbContext /// protected virtual void EntityService(PropertyInfo property, EntityColumnInfo column) { + // 自动 Nullable + if (new NullabilityInfoContext().Create(property).WriteState is NullabilityState.Nullable) + { + column.IsNullable = true; + } + if (property.PropertyType == typeof(ExtraPropertyDictionary)) { column.IsIgnore = true;