Browse Source

Update global filter

pull/30/head
sunkaixuan 2 years ago
parent
commit
3e75003a34
  1. 19
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

19
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -413,15 +413,13 @@ namespace SqlSugar
var isSameName =!isSingle&& this.JoinQueryInfos.Count(it => it.TableName == entityInfo.DbTableName)>0; var isSameName =!isSingle&& this.JoinQueryInfos.Count(it => it.TableName == entityInfo.DbTableName)>0;
if (isSameName) if (isSameName)
{ {
List<string> mysqls = new List<string>();
var mysql = GetSql(exp, isSingle); var mysql = GetSql(exp, isSingle);
foreach (var joinInfoItem in this.JoinQueryInfos.Where(it => it.TableName == entityInfo.DbTableName)) foreach (var joinInfoItem in this.JoinQueryInfos.Where(it => it.TableName == entityInfo.DbTableName))
{ {
var addSql = mysql.Replace(itName, this.Builder.GetTranslationColumnName(joinInfoItem.ShortName)+"."); var addSql = mysql.Replace(itName, this.Builder.GetTranslationColumnName(joinInfoItem.ShortName)+".");
mysqls.Add(Regex.Replace(addSql,"^ (WHERE|AND) ","")); joinInfoItem.JoinWhere+= (" AND "+Regex.Replace(addSql,"^ (WHERE|AND) ",""));
} }
mysqls.Insert(0,mysql.Replace(itName, this.Builder.GetTranslationColumnName(TableShortName)+ ".")); sql = mysql.Replace(itName, this.Builder.GetTranslationColumnName(TableShortName) + ".");
sql = string.Join(" AND ", mysqls);
} }
else else
{ {
@ -462,15 +460,22 @@ namespace SqlSugar
} }
else else
{ {
var isSameName = !isSingle && this.JoinQueryInfos.Count(it => it.TableName == entityInfo.DbTableName) > 1;
foreach (var joinInfo in this.JoinQueryInfos) foreach (var joinInfo in this.JoinQueryInfos)
{ {
if (joinInfo.TableName.EqualCase(entityInfo.EntityName)|| joinInfo.TableName.EqualCase(entityInfo.DbTableName)) if (joinInfo.TableName.EqualCase(entityInfo.EntityName)|| joinInfo.TableName.EqualCase(entityInfo.DbTableName))
{ {
if (sql.StartsWith(" WHERE ")) var mysql = sql;
if (isSameName)
{ {
sql = Regex.Replace(sql, $"^ WHERE ", " AND "); var firstShortName = this.JoinQueryInfos.First(it => it.TableName == entityInfo.DbTableName).ShortName;
mysql = mysql.Replace(Builder.GetTranslationColumnName(firstShortName), Builder.GetTranslationColumnName(joinInfo.ShortName));
} }
joinInfo.JoinWhere=joinInfo.JoinWhere + sql; if (mysql.StartsWith(" WHERE "))
{
mysql = Regex.Replace(mysql, $"^ WHERE ", " AND ");
}
joinInfo.JoinWhere=joinInfo.JoinWhere + mysql;
} }
} }
} }

Loading…
Cancel
Save