mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- fix: AsTable for Select
This commit is contained in:
parent
932b8fde58
commit
b9a21f6c11
@ -75,9 +75,6 @@ namespace FreeSql.DataAnnotations
|
|||||||
|
|
||||||
public interface IAsTable
|
public interface IAsTable
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 所有分表名
|
|
||||||
/// </summary>
|
|
||||||
string[] AllTables { get; }
|
string[] AllTables { get; }
|
||||||
string GetTableNameByColumnValue(object columnValue, bool autoExpand = false);
|
string GetTableNameByColumnValue(object columnValue, bool autoExpand = false);
|
||||||
string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2);
|
string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2);
|
||||||
|
@ -460,13 +460,14 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
protected List<Dictionary<Type, string>> GetTableRuleUnions()
|
protected List<Dictionary<Type, string>> GetTableRuleUnions()
|
||||||
{
|
{
|
||||||
var unions = new List<Dictionary<Type, string>>();
|
var unions = new List<Dictionary<Type, string>>();
|
||||||
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>();
|
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>(new [] { new Func<Type, string, string>((type, oldname) => null) });
|
||||||
|
|
||||||
if (trs.Any() == false)
|
if (trs.Count == 1 && _tables.Any(a => a.Table.AsTableImpl != null && string.IsNullOrWhiteSpace(trs[0](a.Table.Type, a.Table.DbName)) == true))
|
||||||
{
|
{
|
||||||
string[] LocalGetTableNames(SelectTableInfo tb)
|
string[] LocalGetTableNames(SelectTableInfo tb)
|
||||||
{
|
{
|
||||||
if (tb.Table.AsTableImpl != null)
|
var trname = trs[0](tb.Table.Type, tb.Table.DbName);
|
||||||
|
if (tb.Table.AsTableImpl != null && string.IsNullOrWhiteSpace(trname) == true)
|
||||||
{
|
{
|
||||||
string[] aret = null;
|
string[] aret = null;
|
||||||
if (_where.Length == 0) aret = tb.Table.AsTableImpl.AllTables;
|
if (_where.Length == 0) aret = tb.Table.AsTableImpl.AllTables;
|
||||||
@ -481,6 +482,18 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
}
|
}
|
||||||
return aret;
|
return aret;
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(trname) == false)
|
||||||
|
{
|
||||||
|
if (trname.IndexOf(' ') == -1) //还可以这样:select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList()
|
||||||
|
{
|
||||||
|
if (_orm.CodeFirst.IsSyncStructureToLower) trname = trname.ToLower();
|
||||||
|
if (_orm.CodeFirst.IsSyncStructureToUpper) trname = trname.ToUpper();
|
||||||
|
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(tb.Table.Type, trname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
trname = trname.Replace(" \r\n", " \r\n ");
|
||||||
|
return new string[] { trname };
|
||||||
|
}
|
||||||
return new string[] { tb.Table.DbName };
|
return new string[] { tb.Table.DbName };
|
||||||
}
|
}
|
||||||
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();
|
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user