添加 PostgreSQL 数据库的配置,并新增驼峰转下划线功能

This commit is contained in:
Your Name
2024-10-06 03:32:34 +08:00
parent 13120712b1
commit 571b610417
7 changed files with 83 additions and 63 deletions

View File

@@ -19,7 +19,10 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
/// </summary>
public bool EnabledDbSeed { get; set; } = false;
/// <summary>
/// 开启驼峰转下划线
/// </summary>
public bool EnableUnderLine { get; set; } = false;
/// <summary>
/// 开启codefirst

View File

@@ -64,6 +64,12 @@ namespace Yi.Framework.SqlSugarCore
//设置codefirst非空值判断
ConfigureExternalServices = new ConfigureExternalServices
{
// 处理表
EntityNameService = (type, entity) =>
{
if (dbConnOptions.EnableUnderLine && !entity.DbTableName.Contains('_'))
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName);// 驼峰转下划线
},
EntityService = (c, p) =>
{
if (new NullabilityInfoContext()
@@ -72,6 +78,9 @@ namespace Yi.Framework.SqlSugarCore
p.IsNullable = true;
}
if (dbConnOptions.EnableUnderLine && !p.IsIgnore && !p.DbColumnName.Contains('_'))
p.DbColumnName = UtilMethods.ToUnderLine(p.DbColumnName);// 驼峰转下划线
EntityService(c, p);
}
},