From 99c3cd4ff6ed90bbaa28772fd0f4eac530407dc0 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Wed, 22 Nov 2023 21:52:53 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20IAsTable.SetTableName?= =?UTF-8?q?=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=86=E8=A1=A8=E5=90=8D?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/base_entity/ModAsTableImpl.cs | 5 +++++ Examples/base_entity/Program.cs | 8 ++++++-- FreeSql/DataAnnotations/TableAttribute.cs | 13 +++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Examples/base_entity/ModAsTableImpl.cs b/Examples/base_entity/ModAsTableImpl.cs index 3c802b21..312529e2 100644 --- a/Examples/base_entity/ModAsTableImpl.cs +++ b/Examples/base_entity/ModAsTableImpl.cs @@ -42,4 +42,9 @@ class ModAsTableImpl : IAsTable if (tables.Any() == false) return AllTables; return tables; } + + 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 5b8532ae..2dee5906 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -601,8 +601,12 @@ namespace base_entity #endregion fsql.Select().Where(a => a.createtime > DateTime.Now && a.createtime < DateTime.Now.AddMonths(1)).ToList(); - //var table = fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)); - //table.SetAsTable(new ModAsTableImpl(fsql), table.ColumnsByCs[nameof(AsTableLog.click)]); + //var table = fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)); + //table.SetAsTable(new ModAsTableImpl(fsql), table.ColumnsByCs[nameof(AsTableLog.click)]); + + fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)).AsTableImpl + .SetTableName(0, "AsTableLog1") + .SetTableName(1, "AsTableLog2"); var testitems = new[] { diff --git a/FreeSql/DataAnnotations/TableAttribute.cs b/FreeSql/DataAnnotations/TableAttribute.cs index cb2f5f74..8be8f3c0 100644 --- a/FreeSql/DataAnnotations/TableAttribute.cs +++ b/FreeSql/DataAnnotations/TableAttribute.cs @@ -86,7 +86,8 @@ namespace FreeSql.DataAnnotations public interface IAsTable { string[] AllTables { get; } - string GetTableNameByColumnValue(object columnValue, bool autoExpand = false); + IAsTable SetTableName(int index, string tableName); + string GetTableNameByColumnValue(object columnValue, bool autoExpand = false); string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2); string[] GetTableNamesBySqlWhere(string sqlWhere, List dbParams, SelectTableInfo tb, CommonUtils commonUtils); } @@ -377,5 +378,13 @@ namespace FreeSql.DataAnnotations } } } - } + public IAsTable SetTableName(int index, string tableName) + { + lock (_lock) + { + _allTables[index] = tableName; + } + return this; + } + } }