From 41555969335b386fd4c792d431e1bc83f290a015 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Mon, 11 Dec 2023 16:48:02 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=86=E8=A1=A8=20IAsTable.SetDefaultAllTables=20=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E6=9C=AA=E4=BD=BF=E7=94=A8=20where=20=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=9C=BA=E6=99=AF=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20=E8=87=AA=E5=8A=A8=E5=88=86=E8=A1=A8=20=20IAsTable.SetTableN?= =?UTF-8?q?ame=20=E4=BD=8D=E7=BD=AE=20bug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/base_entity/ModAsTableImpl.cs | 6 +- Examples/base_entity/Program.cs | 7 +- FreeSql.DbContext/FreeSql.DbContext.xml | 9 +++ FreeSql/DataAnnotations/TableAttribute.cs | 50 +++++++----- FreeSql/FreeSql.xml | 98 ----------------------- 5 files changed, 50 insertions(+), 120 deletions(-) diff --git a/Examples/base_entity/ModAsTableImpl.cs b/Examples/base_entity/ModAsTableImpl.cs index 312529e2..295ab4ed 100644 --- a/Examples/base_entity/ModAsTableImpl.cs +++ b/Examples/base_entity/ModAsTableImpl.cs @@ -23,7 +23,7 @@ class ModAsTableImpl : IAsTable public string[] AllTables { get; } - public string GetTableNameByColumnValue(object columnValue, bool autoExpand = false) + public string GetTableNameByColumnValue(object columnValue, bool autoExpand = false) { var modid = (int)columnValue; return $"order_{(modid % 10)}"; @@ -43,6 +43,10 @@ class ModAsTableImpl : IAsTable return tables; } + public IAsTable SetDefaultAllTables(Func audit) + { + throw new NotImplementedException(); + } public IAsTable SetTableName(int index, string tableName) { throw new NotImplementedException(); diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 5dda7832..3bde4089 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -618,7 +618,12 @@ namespace base_entity fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)).AsTableImpl .SetTableName(0, "AsTableLog1") - .SetTableName(1, "AsTableLog2"); + .SetTableName(1, "AsTableLog2") + .SetDefaultAllTables(value => + { + if (value.Length > 3) return value.Take(3).ToArray(); + return value; + }); var testitems = new[] { diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 537315e2..26522f10 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -800,5 +800,14 @@ + + + 批量注入 Repository,可以参考代码自行调整 + + + + + + diff --git a/FreeSql/DataAnnotations/TableAttribute.cs b/FreeSql/DataAnnotations/TableAttribute.cs index 8be8f3c0..3499b8d9 100644 --- a/FreeSql/DataAnnotations/TableAttribute.cs +++ b/FreeSql/DataAnnotations/TableAttribute.cs @@ -90,7 +90,8 @@ namespace FreeSql.DataAnnotations string GetTableNameByColumnValue(object columnValue, bool autoExpand = false); string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2); string[] GetTableNamesBySqlWhere(string sqlWhere, List dbParams, SelectTableInfo tb, CommonUtils commonUtils); - } + IAsTable SetDefaultAllTables(Func audit); + } class DateTimeAsTableImpl : IAsTable { readonly object _lock = new object(); @@ -239,23 +240,31 @@ namespace FreeSql.DataAnnotations }; }); } - /// - /// 可以匹配以下条件(支持参数化): - /// `field` BETWEEN '2022-01-01 00:00:00' AND '2022-03-01 00:00:00' - /// `field` > '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00' - /// `field` > '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00' - /// `field` >= '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00' - /// `field` >= '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00' - /// `field` > '2022-01-01 00:00:00' - /// `field` >= '2022-01-01 00:00:00' - /// `field` < '2022-01-01 00:00:00' - /// `field` <= '2022-01-01 00:00:00' - /// - /// - /// - public string[] GetTableNamesBySqlWhere(string sqlWhere, List dbParams, SelectTableInfo tb, CommonUtils commonUtils) + + Func _GetDefaultAllTables; + public IAsTable SetDefaultAllTables(Func audit) { - if (string.IsNullOrWhiteSpace(sqlWhere)) return AllTables; + _GetDefaultAllTables = audit; + return this; + } + + /// + /// 可以匹配以下条件(支持参数化): + /// `field` BETWEEN '2022-01-01 00:00:00' AND '2022-03-01 00:00:00' + /// `field` > '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00' + /// `field` > '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00' + /// `field` >= '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00' + /// `field` >= '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00' + /// `field` > '2022-01-01 00:00:00' + /// `field` >= '2022-01-01 00:00:00' + /// `field` < '2022-01-01 00:00:00' + /// `field` <= '2022-01-01 00:00:00' + /// + /// + /// + public string[] GetTableNamesBySqlWhere(string sqlWhere, List dbParams, SelectTableInfo tb, CommonUtils commonUtils) + { + if (string.IsNullOrWhiteSpace(sqlWhere)) return _GetDefaultAllTables?.Invoke(AllTables) ?? AllTables; var quoteParameterName = ""; if (commonUtils._orm.Ado.DataType == DataType.ClickHouse) quoteParameterName = "@"; //特殊处理 Clickhouse 参数化 else quoteParameterName = commonUtils.QuoteParamterName(""); @@ -299,7 +308,7 @@ namespace FreeSql.DataAnnotations if (val1 == null) throw new Exception(CoreStrings.Failed_SubTable_FieldValue(sqlWhere)); return LocalGetTables2(m.Groups[1].Value, ParseColumnValue(val1)); } - return AllTables; + return _GetDefaultAllTables?.Invoke(AllTables) ?? AllTables; object LocalGetParamValue(string paramName) { @@ -345,7 +354,7 @@ namespace FreeSql.DataAnnotations } break; } - return AllTables; + return _GetDefaultAllTables?.Invoke(AllTables) ?? AllTables; } string[] LocalGetTables2(string opt, DateTime val1) { @@ -364,7 +373,7 @@ namespace FreeSql.DataAnnotations case ">=": return GetTableNamesByColumnValueRange(val1, _lastTime); } - return AllTables; + return _GetDefaultAllTables?.Invoke(AllTables) ?? AllTables; } } @@ -382,6 +391,7 @@ namespace FreeSql.DataAnnotations { lock (_lock) { + index = _allTables.Count - 1 - index; _allTables[index] = tableName; } return this; diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index ed01ba68..c423ca76 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -1104,82 +1104,6 @@ - - - 动态创建实体类型 - - - - - 配置Class - - 类名 - 类标记的特性[Table(Name = "xxx")] [Index(xxxx)] - - - - - 配置属性 - - 属性名称 - 属性类型 - 属性标记的特性-支持多个 - - - - - 配置属性 - - 属性名称 - 属性类型 - 该属性是否重写父类属性 - 属性标记的特性-支持多个 - - - - - 配置属性 - - 属性名称 - 属性类型 - 该属性是否重写父类属性 - 属性默认值 - 属性标记的特性-支持多个 - - - - - 配置父类 - - 父类类型 - - - - - Override属性 - - - - - - Emit动态创建出Class - Type - - - - - - 首字母小写 - - - - - - - 首字母大写 - - - - 获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null @@ -5884,28 +5808,6 @@ 请使用 fsql.InsertDict(dict) 方法插入字典数据 - - - 动态构建Class Type - - - - - - 根据字典,创建 table 对应的实体对象 - - - - - - - - 根据实体对象,创建 table 对应的字典 - - - - - C#: that >= between && that <= and