diff --git a/XCode/DataAccessLayer/Common/DbBase.cs b/XCode/DataAccessLayer/Common/DbBase.cs
index 59d0df382..9bd9ebdcf 100755
--- a/XCode/DataAccessLayer/Common/DbBase.cs
+++ b/XCode/DataAccessLayer/Common/DbBase.cs
@@ -287,6 +287,9 @@ public virtual String ServerVersion
/// 性能追踪器
public ITracer? Tracer { get; set; }
+
+ /// 数据库引擎默认的反向工程表名、字段名大小写设置
+ public virtual NameFormats DefaultNameFormat => NameFormats.None;
#endregion
#region 方法
@@ -704,23 +707,26 @@ public virtual String FormatName(IDataTable table, Boolean formatKeyword)
if (!pf.IsNullOrEmpty()) name = pf + name;
// 名称格式化,只有表名跟名称相同时才处理。否则认为用户指定了表名
- switch (NameFormat)
+ if (table.TableName == table.Name)
{
- case NameFormats.Upper:
- name = name.ToUpper();
- break;
- case NameFormats.Lower:
- name = name.ToLower();
- break;
- case NameFormats.Underline:
- if (table.TableName == table.Name)
- name = ChangeUnderline(name).ToLower();
- else
- name = name.ToLower();
- break;
- case NameFormats.Default:
- default:
- break;
+ var fmt = this.DefaultNameFormat;
+ if (this.NameFormat != NameFormats.Default) fmt = this.NameFormat;
+ switch (fmt)
+ {
+ case NameFormats.Upper:
+ name = name.ToUpperInvariant();
+ break;
+ case NameFormats.Lower:
+ name = name.ToLowerInvariant();
+ break;
+ case NameFormats.Underline:
+ name = ChangeUnderline(name).ToLowerInvariant();
+ break;
+ case NameFormats.Default:
+ case NameFormats.None:
+ default:
+ break;
+ }
}
return formatKeyword ? FormatName(name) : name;
@@ -736,23 +742,26 @@ public virtual String FormatName(IDataColumn column)
var name = column.ColumnName;
// 名称格式化,只有字段名名跟名称相同时才处理。否则认为用户指定了字段名
- switch (NameFormat)
+ if (column.ColumnName == column.Name)
{
- case NameFormats.Upper:
- name = name.ToUpper();
- break;
- case NameFormats.Lower:
- name = name.ToLower();
- break;
- case NameFormats.Underline:
- if (column.ColumnName == column.Name)
- name = ChangeUnderline(name).ToLower();
- else
- name = name.ToLower();
- break;
- case NameFormats.Default:
- default:
- break;
+ var fmt = this.DefaultNameFormat;
+ if (this.NameFormat != NameFormats.Default) fmt = this.NameFormat;
+ switch (fmt)
+ {
+ case NameFormats.Upper:
+ name = name.ToUpperInvariant();
+ break;
+ case NameFormats.Lower:
+ name = name.ToLowerInvariant();
+ break;
+ case NameFormats.Underline:
+ name = ChangeUnderline(name).ToLowerInvariant();
+ break;
+ case NameFormats.Default:
+ case NameFormats.None:
+ default:
+ break;
+ }
}
return FormatName(name);
diff --git a/XCode/DataAccessLayer/Common/IDatabase.cs b/XCode/DataAccessLayer/Common/IDatabase.cs
index 199a544ca..0ec5c571b 100644
--- a/XCode/DataAccessLayer/Common/IDatabase.cs
+++ b/XCode/DataAccessLayer/Common/IDatabase.cs
@@ -23,9 +23,10 @@ public enum Migration
/// 名称格式化
public enum NameFormats
{
- /// 原样
+ /// 默认
Default = 0,
-
+ /// 保持原样
+ None,
/// 全大写
Upper,
diff --git a/XCode/DataAccessLayer/Database/PostgreSQL.cs b/XCode/DataAccessLayer/Database/PostgreSQL.cs
index bcddc35e1..2b76de475 100644
--- a/XCode/DataAccessLayer/Database/PostgreSQL.cs
+++ b/XCode/DataAccessLayer/Database/PostgreSQL.cs
@@ -208,20 +208,17 @@ private string ValueToSQL(Type? type, bool isNullable, object? value)
///
public override String StringConcat(String left, String right) => (!String.IsNullOrEmpty(left) ? left : "''") + "||" + (!String.IsNullOrEmpty(right) ? right : "''");
- ///
- /// 格式化数据库名称,表名称,字段名称 增加双引号("")
- /// PGSQL 默认情况下创建库表时自动转为小写,增加引号强制区分大小写
- /// 以解决数据库创建查询时大小写问题
- ///
- ///
- ///
+ ///
public override String FormatName(String name)
{
name = base.FormatName(name);
if (name.StartsWith("\"") || name.EndsWith("\"")) return name;
- return $"\"{name}\"";
+ //如果包含大写字符,就加上引号
+ if (name.Any(char.IsUpper)) return $"\"{name}\"";
+
+ return name;
}
///
diff --git a/XCode/Setting.cs b/XCode/Setting.cs
index d3c7bfd46..d62aacf8c 100644
--- a/XCode/Setting.cs
+++ b/XCode/Setting.cs
@@ -74,7 +74,7 @@ public class XCodeSetting : Config
public Migration Migration { get; set; } = Migration.On;
///
- [Description("表名称、字段名大小写格式。Default 根据模型生成;Upper 全大写;Lower 全小写;Underline下划线")]
+ [Description("表名称、字段名大小写格式。Default 默认(由数据库决定);None 与模型保持一致;Upper 全大写;Lower 全小写;Underline下划线")]
public NameFormats NameFormat { get; set; } = NameFormats.Default;
/// 全表查行数下限。在获取数据表行数时,先根据索引表进行快速统计。如果快速统计的结果大于该值,则使用快速统计的结果。反之则进行 count(*) 操作获取精确统计。默认1000万