mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update TDengine Stable CodeFirst
This commit is contained in:
parent
d8b0f13916
commit
bc269029dc
12
Src/Asp.NetCore2/SqlSugar.TDengineCore/STableAttribute.cs
Normal file
12
Src/Asp.NetCore2/SqlSugar.TDengineCore/STableAttribute.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengine
|
||||
{
|
||||
public class STableAttribute:Attribute
|
||||
{
|
||||
public string Tags { get; set; }
|
||||
public string STablelName { get; set; }
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengine
|
||||
@ -119,12 +120,19 @@ namespace SqlSugar.TDengine
|
||||
public override void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
List<DbColumnInfo> dbColumns = new List<DbColumnInfo>();
|
||||
foreach (var item in entityInfo.Columns.Where(it=>it.PropertyName!= "TagsTypeId").OrderBy(it=>it.UnderType==typeof(DateTime)?0:1))
|
||||
foreach (var item in entityInfo.Columns.Where(it=>it.IsIgnore!=true).Where(it=>it.PropertyName!= "TagsTypeId").OrderBy(it=>it.UnderType==typeof(DateTime)?0:1))
|
||||
{
|
||||
var addItem = EntityColumnToDbColumn(entityInfo, entityInfo.DbTableName, item);
|
||||
dbColumns.Add(addItem);
|
||||
}
|
||||
var attr = entityInfo.Type.GetCustomAttribute<STableAttribute>();
|
||||
var oldTableName = entityInfo.DbTableName;
|
||||
if (attr != null)
|
||||
{
|
||||
entityInfo.DbTableName += ("{stable}"+this.Context.Utilities.SerializeObject(attr));
|
||||
}
|
||||
this.Context.DbMaintenance.CreateTable(entityInfo.DbTableName, dbColumns);
|
||||
entityInfo.DbTableName = oldTableName;
|
||||
}
|
||||
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
|
@ -328,7 +328,7 @@ namespace SqlSugar.TDengine
|
||||
db.DbMaintenance.AddColumnRemark(item.DbColumnName, item.DbTableName, item.ColumnDescription);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//table remak
|
||||
if (entity.TableDescription != null)
|
||||
{
|
||||
@ -414,6 +414,15 @@ namespace SqlSugar.TDengine
|
||||
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName("STable_"+tableName.ToLower(isAutoToLowerCodeFirst)), string.Join(",\r\n", columnArray));
|
||||
var childTableName = this.SqlBuilder.GetTranslationTableName(tableName.ToLower(isAutoToLowerCodeFirst));
|
||||
var stableName = this.SqlBuilder.GetTranslationTableName("STable_"+tableName.ToLower(isAutoToLowerCodeFirst));
|
||||
var isAttr = tableName.Contains("{stable}");
|
||||
if (isAttr)
|
||||
{
|
||||
var attr = this.Context.Utilities.DeserializeObject<STableAttribute>(tableName.Split("{stable}").Last());
|
||||
stableName= this.SqlBuilder.GetTranslationTableName(attr.STablelName.ToLower(isAutoToLowerCodeFirst));
|
||||
tableString = string.Format(this.CreateTableSql, stableName, string.Join(",\r\n", columnArray));
|
||||
tableName=childTableName = this.SqlBuilder.GetTranslationTableName(tableName.Split("{stable}").First().ToLower(isAutoToLowerCodeFirst));
|
||||
STable.Tags =this.Context.Utilities.DeserializeObject<List<ColumnTagInfo>>( attr.Tags);
|
||||
}
|
||||
if (STable.Tags?.Any() == true)
|
||||
{
|
||||
var colums = STable.Tags.Select(it => this.SqlBuilder.GetTranslationTableName(it.Name)+ " VARCHAR(20) ");
|
||||
|
Loading…
Reference in New Issue
Block a user