mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Update TDengine
This commit is contained in:
parent
128a7ac8a3
commit
6bde63bb39
@ -18,7 +18,24 @@ namespace SqlSugar.TDengine
|
||||
var tableName = GetTableName(entityInfo);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName, false);
|
||||
ConvertColumns(dbColumns);
|
||||
var attr = entityInfo.Type.GetCustomAttribute<STableAttribute>();
|
||||
var entityColumns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
if (attr != null && attr.Tag1 != null)
|
||||
{
|
||||
entityColumns = entityInfo.Columns.Where(it => it.IsIgnore == false
|
||||
|| it.DbColumnName?.ToLower() == attr.Tag1?.ToLower()
|
||||
|| it.DbColumnName?.ToLower() == attr.Tag2?.ToLower()
|
||||
|| it.DbColumnName?.ToLower() == attr.Tag3?.ToLower()
|
||||
|| it.DbColumnName?.ToLower() == attr.Tag4?.ToLower()
|
||||
).ToList();
|
||||
foreach (var item in entityColumns)
|
||||
{
|
||||
if (item.DbColumnName == null)
|
||||
{
|
||||
item.DbColumnName = item.PropertyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
var dropColumns = dbColumns
|
||||
.Where(dc => !entityColumns.Any(ec => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.Where(dc => !entityColumns.Any(ec => dc.DbColumnName.Equals(ec.DbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
|
@ -0,0 +1,45 @@
|
||||
using SqlSugar.TDengine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class TagInserttable<T> where T : class, new()
|
||||
{
|
||||
internal IInsertable<T> thisValue;
|
||||
internal Func<string, T, string> getChildTableNamefunc;
|
||||
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
var provider = (InsertableProvider<T>) thisValue;
|
||||
var inserObjects = provider.InsertObjs;
|
||||
var attr = typeof(T).GetCustomAttribute<STableAttribute>();
|
||||
Check.ExceptionEasy(attr == null|| attr?.Tag1==null, $"", $"{nameof(T)}缺少特性STableAttribute和Tag1");
|
||||
// 根据所有非空的 Tag 进行分组
|
||||
var groups = inserObjects.GroupBy(it =>
|
||||
{
|
||||
// 动态生成分组键
|
||||
var groupKey = new List<string>();
|
||||
|
||||
if (attr.Tag1 != null)
|
||||
groupKey.Add(it.GetType().GetProperty(attr.Tag1)?.GetValue(it)?.ToString());
|
||||
|
||||
if (attr.Tag2 != null)
|
||||
groupKey.Add(it.GetType().GetProperty(attr.Tag2)?.GetValue(it)?.ToString());
|
||||
|
||||
if (attr.Tag3 != null)
|
||||
groupKey.Add(it.GetType().GetProperty(attr.Tag3)?.GetValue(it)?.ToString());
|
||||
|
||||
if (attr.Tag4 != null)
|
||||
groupKey.Add(it.GetType().GetProperty(attr.Tag4)?.GetValue(it)?.ToString());
|
||||
|
||||
// 将非空的 Tag 值用下划线连接作为分组键
|
||||
return string.Join("_", groupKey.Where(k => !string.IsNullOrEmpty(k)));
|
||||
});
|
||||
return inserObjects.Count();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,13 @@ namespace SqlSugar.TDengine
|
||||
/// </summary>
|
||||
public static class UtilExtensions
|
||||
{
|
||||
public static TagInserttable<T> SetTDengineChildTableName<T>(this IInsertable<T> thisValue,Func<string,T,string> getChildTableNamefunc) where T:class,new()
|
||||
{
|
||||
TagInserttable<T> result = new TagInserttable<T>();
|
||||
result.thisValue = thisValue;
|
||||
result.getChildTableNamefunc = getChildTableNamefunc;
|
||||
return result;
|
||||
}
|
||||
public static string ObjToStringNoTrim(this object thisValue)
|
||||
{
|
||||
if (thisValue != null) return thisValue.ToString();
|
||||
|
Loading…
Reference in New Issue
Block a user