mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-12-25 01:35:47 +08:00
initial commit
This commit is contained in:
54
Examples/base_entity/ModAsTableImpl.cs
Normal file
54
Examples/base_entity/ModAsTableImpl.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using FreeSql;
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class ModAsTableImpl : IAsTable
|
||||
{
|
||||
public ModAsTableImpl(IFreeSql fsql)
|
||||
{
|
||||
AllTables = Enumerable.Range(0, 9).Select(a => $"order_{a}").ToArray();
|
||||
fsql.Aop.CommandBefore += (_, e) =>
|
||||
{
|
||||
e.Command.CommandText = Regex.Replace(e.Command.CommandText, @"/\*astable\([^\)]+\)*\/", "1=1");
|
||||
};
|
||||
}
|
||||
|
||||
public string[] AllTables { get; }
|
||||
|
||||
public string GetTableNameByColumnValue(object columnValue, bool autoExpand = false)
|
||||
{
|
||||
var modid = (int)columnValue;
|
||||
return $"order_{(modid % 10)}";
|
||||
}
|
||||
|
||||
public string[] GetTableNamesByColumnValueRange(object columnValue1, object columnValue2)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IAsTableTableNameRangeResult GetTableNamesBySqlWhere(string sqlWhere, List<DbParameter> dbParams, SelectTableInfo tb, CommonUtils commonUtils)
|
||||
{
|
||||
var match = Regex.Match(sqlWhere, @"/\*astable\([^\)]+\)*\/");
|
||||
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 new IAsTableTableNameRangeResult(AllTables, null, null);
|
||||
return new IAsTableTableNameRangeResult(tables, null, null);
|
||||
}
|
||||
|
||||
public IAsTable SetDefaultAllTables(Func<string[], string[]> audit)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public IAsTable SetTableName(int index, string tableName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user