mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 优化 自动分表 join 分表(自动贴合);
This commit is contained in:
@ -34,14 +34,14 @@ class ModAsTableImpl : IAsTable
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string[] GetTableNamesBySqlWhere(string sqlWhere, List<DbParameter> dbParams, SelectTableInfo tb, CommonUtils commonUtils)
|
||||
public IAsTableTableNameRangeResult GetTableNamesBySqlWhere(string sqlWhere, List<DbParameter> dbParams, SelectTableInfo tb, CommonUtils commonUtils)
|
||||
{
|
||||
var match = Regex.Match(sqlWhere, @"/\*astable\([^\)]+\)*\/");
|
||||
if (match.Success == false) return AllTables;
|
||||
if (match.Success == false) return new IAsTableTableNameRangeResult(AllTables, null, null);
|
||||
var tables = match.Groups[1].Value.Split(',').Where(a => AllTables.Contains(a)).ToArray();
|
||||
if (tables.Any() == false) return AllTables;
|
||||
return tables;
|
||||
}
|
||||
if (tables.Any() == false) return new IAsTableTableNameRangeResult(AllTables, null, null);
|
||||
return new IAsTableTableNameRangeResult(tables, null, null);
|
||||
}
|
||||
|
||||
public IAsTable SetDefaultAllTables(Func<string[], string[]> audit)
|
||||
{
|
||||
|
@ -116,9 +116,17 @@ namespace base_entity
|
||||
public string msg { get; set; }
|
||||
public DateTime createtime { get; set; }
|
||||
public int click { get; set; }
|
||||
}
|
||||
}
|
||||
[Table(Name = "as_table_logext_{yyyyMMddHH}", AsTable = "createtime=2022-1-1 11(12,2 month)")]
|
||||
class AsTableLogExt
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string msg { get; set; }
|
||||
public DateTime createtime { get; set; }
|
||||
public int click { get; set; }
|
||||
}
|
||||
|
||||
public class SomeEntity
|
||||
public class SomeEntity
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
@ -619,13 +627,37 @@ namespace base_entity
|
||||
fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)).AsTableImpl
|
||||
.SetTableName(0, "AsTableLog1")
|
||||
.SetTableName(1, "AsTableLog2")
|
||||
//.SetDefaultAllTables(value =>
|
||||
//{
|
||||
// if (value.Length > 3) return value.Take(3).ToArray();
|
||||
// return value;
|
||||
//})
|
||||
.SetDefaultAllTables(value =>
|
||||
{
|
||||
if (value.Length > 3) return value.Take(3).ToArray();
|
||||
return value;
|
||||
})
|
||||
;
|
||||
|
||||
|
||||
var astsql01 = fsql.Select<AsTableLog, Sys_owner>()
|
||||
.InnerJoin((a, b) => a.id == b.Id)
|
||||
.OrderBy((a, b) => a.createtime)
|
||||
.ToSql();
|
||||
|
||||
var astsql02 = fsql.Select<Sys_owner, AsTableLog>()
|
||||
.InnerJoin((a, b) => a.Id == b.id)
|
||||
.OrderBy((a, b) => b.createtime)
|
||||
.ToSql();
|
||||
|
||||
var astsql03 = fsql.Select<AsTableLog>()
|
||||
.Where(a => a.createtime < DateTime.Parse("2023-5-1"))
|
||||
.FromQuery(fsql.Select<AsTableLogExt>())
|
||||
.InnerJoin((a, b) => a.id == b.id)
|
||||
.OrderBy((a, b) => a.createtime)
|
||||
.ToSql();
|
||||
|
||||
var astsql04 = fsql.Select<AsTableLog, AsTableLogExt>()
|
||||
.InnerJoin((a, b) => a.id == b.id)
|
||||
.Where((a,b) => a.createtime < DateTime.Parse("2023-5-1"))
|
||||
.OrderBy((a, b) => a.createtime)
|
||||
.ToSql();
|
||||
|
||||
var testitems = new[]
|
||||
{
|
||||
new AsTableLog{ msg = "msg01", createtime = DateTime.Parse("2022-1-1 13:00:11"), click = 1 },
|
||||
@ -1010,10 +1042,6 @@ namespace base_entity
|
||||
var sqlastable2 = fsql.Update<CurrentDetail>(101).AsTable("current_detail_230501").Set(t => t.StatuId, 1).ToSql();
|
||||
var sqlastable3 = fsql.Delete<CurrentDetail>(101).AsTable("current_detail_230501").ToSql();
|
||||
|
||||
var astsql = fsql.Select<AsTableLog, Sys_owner>()
|
||||
.InnerJoin((a, b) => a.id == b.Id)
|
||||
.OrderBy((a, b) => a.createtime)
|
||||
.ToSql();
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user