mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Synchronization code
This commit is contained in:
@@ -82,7 +82,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
MappingTableList oldTableList = CopyMappingTalbe();
|
MappingTableList oldTableList = CopyMappingTalbe();
|
||||||
//this.Context.Utilities.RemoveCacheAll();
|
//this.Context.Utilities.RemoveCacheAll();
|
||||||
this.Context.InitMappingInfoNoCache(entityType);
|
var entityInfo=this.Context.GetEntityNoCacheInitMappingInfo(entityType);
|
||||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||||
{
|
{
|
||||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||||
@@ -93,13 +93,13 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var executeResult = Context.Ado.UseTran(() =>
|
var executeResult = Context.Ado.UseTran(() =>
|
||||||
{
|
{
|
||||||
Execute(entityType);
|
Execute(entityType,entityInfo);
|
||||||
});
|
});
|
||||||
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Execute(entityType);
|
Execute(entityType, entityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
RestMappingTables(oldTableList);
|
RestMappingTables(oldTableList);
|
||||||
@@ -240,9 +240,9 @@ namespace SqlSugar
|
|||||||
db.DbMaintenance.DropTable(tempTableName);
|
db.DbMaintenance.DropTable(tempTableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected virtual void Execute(Type entityType)
|
protected virtual void Execute(Type entityType,EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
||||||
if (entityInfo.Discrimator.HasValue())
|
if (entityInfo.Discrimator.HasValue())
|
||||||
{
|
{
|
||||||
Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格");
|
Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格");
|
||||||
|
@@ -340,6 +340,7 @@ namespace SqlSugar
|
|||||||
value = "empty";
|
value = "empty";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
value = GetDefaultValue(columnInfo, value);
|
||||||
var dt = new Dictionary<string, object>();
|
var dt = new Dictionary<string, object>();
|
||||||
dt.Add(columnInfo.DbColumnName, value);
|
dt.Add(columnInfo.DbColumnName, value);
|
||||||
if (columnInfo.DataType.EqualCase("json") && columnInfo.DefaultValue?.Contains("}") == true)
|
if (columnInfo.DataType.EqualCase("json") && columnInfo.DefaultValue?.Contains("}") == true)
|
||||||
@@ -375,6 +376,14 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public virtual object GetDefaultValue(DbColumnInfo columnInfo, object value)
|
||||||
|
{
|
||||||
|
if (columnInfo.DataType.ObjToString().ToLower().IsIn("varchar", "nvarchar", "varchar2", "nvarchar2") && !string.IsNullOrEmpty(columnInfo.DefaultValue) && Regex.IsMatch(columnInfo.DefaultValue, @"^\w+$"))
|
||||||
|
{
|
||||||
|
value = columnInfo.DefaultValue;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
public virtual bool UpdateColumn(string tableName, DbColumnInfo column)
|
public virtual bool UpdateColumn(string tableName, DbColumnInfo column)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
|
@@ -168,6 +168,12 @@ namespace SqlSugar
|
|||||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
|
||||||
InitMappingInfo(entityInfo);
|
InitMappingInfo(entityInfo);
|
||||||
}
|
}
|
||||||
|
public EntityInfo GetEntityNoCacheInitMappingInfo(Type type)
|
||||||
|
{
|
||||||
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
|
||||||
|
InitMappingInfo(entityInfo);
|
||||||
|
return entityInfo;
|
||||||
|
}
|
||||||
//private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
|
//private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
|
||||||
//{
|
//{
|
||||||
// EntityInfo result = new EntityInfo()
|
// EntityInfo result = new EntityInfo()
|
||||||
|
Reference in New Issue
Block a user