mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-20 04:48:16 +08:00
- 移除 FreeSql.Repository 扩展方法 FromRepository;
- 调整 ISelect.AsTable 规则,每一次使用将增加 UNION ALL 查询; - 优化 AsTable UseSyncStructureToLower/ToUpper 设置,兼容 AsTable((t,o) => "(select * from tb)"); #89
This commit is contained in:
@ -130,13 +130,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (_tableRule == null) return _table.DbName;
|
||||
var newname = _tableRule(_table.DbName);
|
||||
if (!string.IsNullOrEmpty(newname))
|
||||
{
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) return newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) return newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
return _table.DbName;
|
||||
if (string.IsNullOrEmpty(newname)) return _table.DbName;
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) newname = newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) newname = newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
public IDelete<T1> AsTable(Func<string, string> tableRule)
|
||||
{
|
||||
|
@ -552,13 +552,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (_tableRule == null) return _table.DbName;
|
||||
var newname = _tableRule(_table.DbName);
|
||||
if (!string.IsNullOrEmpty(newname))
|
||||
{
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) return newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) return newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
return _table.DbName;
|
||||
if (string.IsNullOrEmpty(newname)) return _table.DbName;
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) newname = newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) newname = newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
public IInsert<T1> AsTable(Func<string, string> tableRule)
|
||||
{
|
||||
|
@ -906,23 +906,33 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return (map, field.ToString());
|
||||
}
|
||||
|
||||
protected string[] TableRuleInvoke(Type type, string oldname)
|
||||
protected List<Dictionary<Type, string>> GetTableRuleUnions()
|
||||
{
|
||||
List<string> newnames = new List<string>();
|
||||
foreach (var tr in _tableRules)
|
||||
var unions = new List<Dictionary<Type, string>>();
|
||||
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>(new[] { new Func<Type, string, string>((type, oldname) => oldname) });
|
||||
foreach (var tr in trs)
|
||||
{
|
||||
var newname = tr?.Invoke(type, oldname);
|
||||
if (!string.IsNullOrEmpty(newname))
|
||||
var dict = new Dictionary<Type, string>();
|
||||
foreach (var tb in _tables)
|
||||
{
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) newnames.Add(newname.ToLower());
|
||||
else if (_orm.CodeFirst.IsSyncStructureToUpper) newnames.Add(newname.ToUpper());
|
||||
else newnames.Add(newname);
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
if (dict.ContainsKey(tb.Table.Type)) continue;
|
||||
var name = tr?.Invoke(tb.Table.Type, tb.Table.DbName);
|
||||
if (string.IsNullOrEmpty(name)) name = tb.Table.DbName;
|
||||
else
|
||||
{
|
||||
if (name.IndexOf(' ') == -1)
|
||||
{
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) name = name.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) name = name.ToUpper();
|
||||
}
|
||||
}
|
||||
dict.Add(tb.Table.Type, name);
|
||||
}
|
||||
unions.Add(dict);
|
||||
}
|
||||
if (newnames.Any() == false) return new[] { oldname };
|
||||
return newnames.Distinct().ToArray();
|
||||
return unions;
|
||||
}
|
||||
|
||||
public TSelect AsTable(Func<Type, string, string> tableRule)
|
||||
{
|
||||
if (tableRule != null) _tableRules.Add(tableRule);
|
||||
|
@ -604,13 +604,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (_tableRule == null) return _table.DbName;
|
||||
var newname = _tableRule(_table.DbName);
|
||||
if (!string.IsNullOrEmpty(newname))
|
||||
{
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) return newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) return newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
return _table.DbName;
|
||||
if (string.IsNullOrEmpty(newname)) return _table.DbName;
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) newname = newname.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) newname = newname.ToUpper();
|
||||
return newname;
|
||||
}
|
||||
public IUpdate<T1> AsTable(Func<string, string> tableRule)
|
||||
{
|
||||
|
@ -363,36 +363,5 @@ namespace FreeSql.Internal
|
||||
}
|
||||
while (initConns.TryTake(out var conn)) pool.Return(conn);
|
||||
}
|
||||
|
||||
public static List<Dictionary<Type, string>> GetAllTableRule(List<SelectTableInfo> _tables, Func<Type, string, string[]> tableRuleInvoke)
|
||||
{
|
||||
var tableRuleSorted = new List<(Type, string[])>();
|
||||
var tableRuleDict = new Dictionary<Type, bool>();
|
||||
foreach(var tb in _tables)
|
||||
{
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
if (tableRuleDict.ContainsKey(tb.Table.Type)) continue;
|
||||
var names = tableRuleInvoke(tb.Table.Type, tb.Table.DbName);
|
||||
tableRuleSorted.Add((tb.Table.Type, names));
|
||||
tableRuleDict.Add(tb.Table.Type, true);
|
||||
}
|
||||
var tableRules = new List<Dictionary<Type, string>>();
|
||||
tableRules.Add(tableRuleSorted.Select(a => (a.Item1, a.Item2.First())).ToDictionary(a => a.Item1, a => a.Item2));
|
||||
for (var z = tableRuleSorted.Count - 1; z >=0; z--)
|
||||
{
|
||||
var tbrd = tableRuleSorted[z];
|
||||
var curpos = tableRules.Count;
|
||||
for (var a = 1; a < tbrd.Item2.Length; a++)
|
||||
{
|
||||
for (var b = 0; b < curpos; b++)
|
||||
{
|
||||
var tr = new Dictionary<Type, string>();
|
||||
foreach (var oldtd in tableRules[b]) tr.Add(oldtd.Key, tbrd.Item1 == oldtd.Key ? tbrd.Item2[a] : oldtd.Value);
|
||||
tableRules.Add(tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tableRules;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user