From 72901097341d0a0f4e02b38c7c94f362a606817e Mon Sep 17 00:00:00 2001
From: 2881099 <2881099@qq.com>
Date: Wed, 1 Jun 2022 09:38:59 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20UseMappingPriority=20?=
=?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=98=A0=E5=B0=84=E4=BC=98=E5=85=88=E7=BA=A7?=
=?UTF-8?q?=EF=BC=9B#387=20#69=20#99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql/FreeSql.xml | 205 +++++++-----
FreeSql/FreeSqlBuilder.cs | 28 ++
FreeSql/Internal/CommonUtils.cs | 301 +++++++++++-------
...gConvertType.cs => FreeSqlBuilderTypes.cs} | 92 ++++--
4 files changed, 399 insertions(+), 227 deletions(-)
rename FreeSql/Internal/{StringConvertType.cs => FreeSqlBuilderTypes.cs} (73%)
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 995ea24d..2db205b7 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -1413,6 +1413,24 @@
+
+
+ 指定映射优先级
+ 例如表名:实体类名 < Aop < FluentApi < Attribute < AsTable
+ 事件 Aop -------> fsql.Aop.ConfigEntity/fsql.Aop.ConfigEntityProperty
+ 方法 FluentApi -> fsql.CodeFirst.ConfigEntity/fsql.CodeFirst.Entity
+ 特性 Attribute -> [Table(Name = xxx, ...)]
+ -----------------------------------------------------------------------------
+ 默认规则:关于映射优先级,Attribute 可以更直观排查问题,即使任何地方使用 FluentApi/Aop 设置 TableName 都不生效。
+ 调整规则:UseMappingPriority(Attribute, FluentApi, Aop)
+ 实体类名 < Attribute < FluentApi < Aop < AsTable
+
+
+
+
+
+
+
监听 AppDomain.CurrentDomain.ProcessExit/Console.CancelKeyPress 事件自动释放连接池
@@ -4037,6 +4055,112 @@
更新的实体
+
+
+ 映射优先级,默认: Attribute > FluentApi > Aop
+
+
+
+
+ 实体特性
+ [Table(Name = "tabname")]
+ [Column(Name = "table_id")]
+
+
+
+
+ 流式接口
+ fsql.CodeFirst.ConfigEntity(a => a.Name("tabname"))
+ fsql.CodeFirst.ConfigEntity(a => a.Property(b => b.Id).Name("table_id"))
+
+
+
+
+ AOP 特性 https://github.com/dotnetcore/FreeSql/wiki/AOP
+ fsql.Aop.ConfigEntity += (_, e) => e.ModifyResult.Name = "public.tabname";
+ fsql.Aop.ConfigEntityProperty += (_, e) => e.ModifyResult.Name = "table_id";
+
+
+
+
+ 不进行任何处理
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串
+
+ BigApple -> Big_Apple
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
+
+ BigApple -> BIG_APPLE
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
+
+ BigApple -> big_apple
+
+
+
+
+ 将字符串转换为大写
+
+ BigApple -> BIGAPPLE
+
+
+
+
+ 将字符串转换为小写
+
+ BigApple -> bigapple
+
+
+
+
+ 不进行任何处理
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串
+
+ BigApple -> Big_Apple
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
+
+ BigApple -> BIG_APPLE
+
+
+
+
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
+
+ BigApple -> big_apple
+
+
+
+
+ 将字符串转换为大写
+
+ BigApple -> BIGAPPLE
+
+
+
+
+ 将字符串转换为小写
+
+ BigApple -> bigapple
+
+
创建一个过滤器
@@ -4336,6 +4460,7 @@
将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用
+
由【可用】变成【不可用】时返回true,否则返回false
@@ -4545,86 +4670,6 @@
-
-
- 不进行任何处理
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串
-
- BigApple -> Big_Apple
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
-
- BigApple -> BIG_APPLE
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
-
- BigApple -> big_apple
-
-
-
-
- 将字符串转换为大写
-
- BigApple -> BIGAPPLE
-
-
-
-
- 将字符串转换为小写
-
- BigApple -> bigapple
-
-
-
-
- 不进行任何处理
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串
-
- BigApple -> Big_Apple
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
-
- BigApple -> BIG_APPLE
-
-
-
-
- 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
-
- BigApple -> big_apple
-
-
-
-
- 将字符串转换为大写
-
- BigApple -> BIGAPPLE
-
-
-
-
- 将字符串转换为小写
-
- BigApple -> bigapple
-
-
diff --git a/FreeSql/FreeSqlBuilder.cs b/FreeSql/FreeSqlBuilder.cs
index ef5feba6..df8f3bc7 100644
--- a/FreeSql/FreeSqlBuilder.cs
+++ b/FreeSql/FreeSqlBuilder.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using FreeSql.DataAnnotations;
using FreeSql.Internal;
+using FreeSql.Internal.CommonProvider;
namespace FreeSql
{
@@ -24,6 +25,7 @@ namespace FreeSql
bool _isGenerateCommandParameterWithLambda = false;
bool _isLazyLoading = false;
bool _isExitAutoDisposePool = true;
+ MappingPriorityType[] _mappingPriorityTypes;
StringConvertType _entityPropertyConvertType = StringConvertType.None;
NameConvertType _nameConvertType = NameConvertType.None;
Action _aopCommandExecuting = null;
@@ -160,6 +162,29 @@ namespace FreeSql
return this;
}
+ ///
+ /// 指定映射优先级
+ /// 例如表名:实体类名 < Aop < FluentApi < Attribute < AsTable
+ /// 事件 Aop -------> fsql.Aop.ConfigEntity/fsql.Aop.ConfigEntityProperty
+ /// 方法 FluentApi -> fsql.CodeFirst.ConfigEntity/fsql.CodeFirst.Entity
+ /// 特性 Attribute -> [Table(Name = xxx, ...)]
+ /// -----------------------------------------------------------------------------
+ /// 默认规则:关于映射优先级,Attribute 可以更直观排查问题,即使任何地方使用 FluentApi/Aop 设置 TableName 都不生效。
+ /// 调整规则:UseMappingPriority(Attribute, FluentApi, Aop)
+ /// 实体类名 < Attribute < FluentApi < Aop < AsTable
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public FreeSqlBuilder UseMappingPriority(MappingPriorityType mappingType1, MappingPriorityType mappingType2, MappingPriorityType mappingType3)
+ {
+ if (mappingType1 == mappingType2 || mappingType1 == mappingType3 || mappingType2 == mappingType3) throw new ArgumentException($"{nameof(mappingType1)}、{nameof(mappingType2)}、{nameof(mappingType3)} 不可以相等");
+ _mappingPriorityTypes = new[] { mappingType1, mappingType2, mappingType3 };
+ return this;
+ }
+
///
/// 监听 AppDomain.CurrentDomain.ProcessExit/Console.CancelKeyPress 事件自动释放连接池
/// 默认值: true
@@ -298,6 +323,9 @@ namespace FreeSql
ret.CodeFirst.IsGenerateCommandParameterWithLambda = _isGenerateCommandParameterWithLambda;
ret.CodeFirst.IsLazyLoading = _isLazyLoading;
+ if (_mappingPriorityTypes != null)
+ (ret.Select
ToLower
}
+
+ public enum StringConvertType
+ {
+ ///
+ /// 不进行任何处理
+ ///
+ None = 0,
+
+ ///
+ /// 将帕斯卡命名字符串转换为下划线分隔字符串
+ ///
+ /// BigApple -> Big_Apple
+ ///
+ PascalCaseToUnderscore,
+
+ ///
+ /// 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
+ ///
+ /// BigApple -> BIG_APPLE
+ ///
+ PascalCaseToUnderscoreWithUpper,
+
+ ///
+ /// 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
+ ///
+ /// BigApple -> big_apple
+ ///
+ PascalCaseToUnderscoreWithLower,
+
+ ///
+ /// 将字符串转换为大写
+ ///
+ /// BigApple -> BIGAPPLE
+ ///
+ Upper,
+
+ ///
+ /// 将字符串转换为小写
+ ///
+ /// BigApple -> bigapple
+ ///
+ Lower
+ }
+
}
\ No newline at end of file