Skip to content

Commit b9a21f6

Browse files
committed
- fix: AsTable for Select
1 parent 932b8fd commit b9a21f6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

FreeSql/DataAnnotations/TableAttribute.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ internal void ParseAsTable(TableInfo tb)
7575

7676
public interface IAsTable
7777
{
78-
/// <summary>
79-
/// 所有分表名
80-
/// </summary>
8178
string[] AllTables { get; }
8279
string GetTableNameByColumnValue(object columnValue, bool autoExpand = false);
8380
string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2);

FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,14 @@ public IUpdate<T1> ToUpdate()
460460
protected List<Dictionary<Type, string>> GetTableRuleUnions()
461461
{
462462
var unions = new List<Dictionary<Type, string>>();
463-
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>();
463+
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>(new [] { new Func<Type, string, string>((type, oldname) => null) });
464464

465-
if (trs.Any() == false)
465+
if (trs.Count == 1 && _tables.Any(a => a.Table.AsTableImpl != null && string.IsNullOrWhiteSpace(trs[0](a.Table.Type, a.Table.DbName)) == true))
466466
{
467467
string[] LocalGetTableNames(SelectTableInfo tb)
468468
{
469-
if (tb.Table.AsTableImpl != null)
469+
var trname = trs[0](tb.Table.Type, tb.Table.DbName);
470+
if (tb.Table.AsTableImpl != null && string.IsNullOrWhiteSpace(trname) == true)
470471
{
471472
string[] aret = null;
472473
if (_where.Length == 0) aret = tb.Table.AsTableImpl.AllTables;
@@ -481,6 +482,18 @@ string[] LocalGetTableNames(SelectTableInfo tb)
481482
}
482483
return aret;
483484
}
485+
if (string.IsNullOrWhiteSpace(trname) == false)
486+
{
487+
if (trname.IndexOf(' ') == -1) //还可以这样:select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList()
488+
{
489+
if (_orm.CodeFirst.IsSyncStructureToLower) trname = trname.ToLower();
490+
if (_orm.CodeFirst.IsSyncStructureToUpper) trname = trname.ToUpper();
491+
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(tb.Table.Type, trname);
492+
}
493+
else
494+
trname = trname.Replace(" \r\n", " \r\n ");
495+
return new string[] { trname };
496+
}
484497
return new string[] { tb.Table.DbName };
485498
}
486499
var tbnames = _tables.GroupBy(a => a.Table.Type).Select(g => _tables.Where(a => a.Table.Type == g.Key).FirstOrDefault()).Select(a => new { Tb = a, Names = LocalGetTableNames(a) }).ToList();

0 commit comments

Comments
 (0)