updated sqlsugar when generate table and column

master
Young 6 months ago
parent e412c6636d
commit e8f79b2996

@ -317,6 +317,7 @@ public static class ServiceCollectionExtensions
this IServiceCollection services, this IServiceCollection services,
IConfiguration configuration, IConfiguration configuration,
IWebHostEnvironment hostEnvironment, IWebHostEnvironment hostEnvironment,
List<ConnectionConfig>? connectionConfigs = null,
Action<object, DataFilterModel>? onDataChanging = null, Action<object, DataFilterModel>? onDataChanging = null,
Action<DiffLogModel>? onDiffLogEvent = null Action<DiffLogModel>? onDiffLogEvent = null
) )
@ -356,21 +357,35 @@ public static class ServiceCollectionExtensions
ArgumentException.ThrowIfNullOrEmpty(password); ArgumentException.ThrowIfNullOrEmpty(password);
var connectionString = $"server={server};port={port};database={database};userid={user};password={password};"; var connectionString = $"server={server};port={port};database={database};userid={user};password={password};";
connectionConfigs ??= [];
var connectionConfig = new ConnectionConfig() connectionConfigs.Add(new ConnectionConfig()
{ {
DbType = DbType.PostgreSQL, DbType = DbType.PostgreSQL,
ConnectionString = connectionString, ConnectionString = connectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings() MoreSettings = new ConnMoreSettings
{ {
PgSqlIsAutoToLower = false, PgSqlIsAutoToLower = false,
PgSqlIsAutoToLowerCodeFirst = false, PgSqlIsAutoToLowerCodeFirst = false,
},
ConfigureExternalServices = new ConfigureExternalServices()
{
EntityService = (p, c) =>
{
if (c.IsPrimarykey == false && new NullabilityInfoContext()
.Create(p).WriteState is NullabilityState.Nullable)
{
c.IsNullable = true;
} }
};
var sugarScope = new SqlSugarScope(connectionConfig, client => c.DbColumnName = UtilMethods.ToUnderLine(c.DbColumnName);
},
EntityNameService = (p, c) => { c.DbTableName = UtilMethods.ToUnderLine(c.DbTableName); }
}
});
var sugarScope = new SqlSugarScope(connectionConfigs, client =>
{ {
client.QueryFilter.AddTableFilter<IDeletable>(d => !d.IsDeleted); client.QueryFilter.AddTableFilter<IDeletable>(d => !d.IsDeleted);
if (hostEnvironment.IsDevelopment() || hostEnvironment.IsStaging()) if (hostEnvironment.IsDevelopment() || hostEnvironment.IsStaging())

Loading…
Cancel
Save