Synchronization code

This commit is contained in:
sunkaixuan 2023-08-12 17:45:34 +08:00
parent 75e6285a54
commit fe2d7f4f99
2 changed files with 23 additions and 1 deletions

View File

@ -657,12 +657,18 @@ namespace SqlSugar
{
shortName = this.Builder.GetTranslationColumnName(shortName);
}
return string.Format(
var result= string.Format(
this.JoinTemplate,
joinInfo.JoinType.ToString() + UtilConstants.Space,
Builder.GetTranslationTableName(name) + UtilConstants.Space,
shortName + UtilConstants.Space + (TableWithString == SqlWith.Null|| isSubQuery ? " " : TableWithString),
joinInfo.JoinWhere);
if (joinInfo.EntityType!=null&&this.Context.EntityMaintenance.GetEntityInfoWithAttr(joinInfo.EntityType).Discrimator.HasValue())
{
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoWithAttr(joinInfo.EntityType);
result = $" {result} AND {shortName}.{UtilMethods.GetDiscrimator(entityInfo,this.Builder)}";
}
return result;
}
public virtual void Clear()
{

View File

@ -1312,6 +1312,22 @@ namespace SqlSugar
}
}
}
internal static string GetDiscrimator(EntityInfo entityInfo,ISqlBuilder builer)
{
List<string> wheres = new List<string>();
if (entityInfo != null && 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不要有空格");
var array = entityInfo.Discrimator.Split(',');
foreach (var disItem in array)
{
var name = disItem.Split(':').First();
var value = disItem.Split(':').Last();
wheres.Add($"{builer.GetTranslationColumnName(name)}={value.ToSqlValue()} ");
}
}
return string.Join(" AND ", wheres);
}
}
}