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

Loading…
Cancel
Save