mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 修复 UpdateJoin 与全局过滤器别名问题;#1612
This commit is contained in:
@ -279,6 +279,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public string ToSql()
|
||||
{
|
||||
_updateProvider._interceptSql = InterceptSql;
|
||||
_updateProvider._tableAlias = _query2Provider._tables[0].Alias;
|
||||
try
|
||||
{
|
||||
return _update.ToSql();
|
||||
@ -286,11 +287,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
finally
|
||||
{
|
||||
_updateProvider._interceptSql = null;
|
||||
_updateProvider._tableAlias = null;
|
||||
}
|
||||
}
|
||||
public int ExecuteAffrows()
|
||||
{
|
||||
_updateProvider._interceptSql = InterceptSql;
|
||||
_updateProvider._tableAlias = _query2Provider._tables[0].Alias;
|
||||
try
|
||||
{
|
||||
return _update.ExecuteAffrows();
|
||||
@ -298,6 +301,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
finally
|
||||
{
|
||||
_updateProvider._interceptSql = null;
|
||||
_updateProvider._tableAlias = null;
|
||||
}
|
||||
}
|
||||
#if net40
|
||||
@ -305,6 +309,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
async public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
_updateProvider._interceptSql = InterceptSql;
|
||||
_updateProvider._tableAlias = _query2Provider._tables[0].Alias;
|
||||
try
|
||||
{
|
||||
return await _update.ExecuteAffrowsAsync(cancellationToken);
|
||||
@ -312,6 +317,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
finally
|
||||
{
|
||||
_updateProvider._interceptSql = null;
|
||||
_updateProvider._tableAlias = null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -37,6 +37,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public DbConnection _connection;
|
||||
public int _commandTimeout = 0;
|
||||
public Action<StringBuilder> _interceptSql;
|
||||
public string _tableAlias;
|
||||
public object _updateVersionValue;
|
||||
public bool _isAutoSyncStructure;
|
||||
|
||||
@ -214,6 +215,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_whereGlobalFilter = _orm.GlobalFilter.GetFilters();
|
||||
_batchProgress = null;
|
||||
_interceptSql = null;
|
||||
_tableAlias = null;
|
||||
_versionColumn = _table?.VersionColumn;
|
||||
_ignoreVersion = false;
|
||||
}
|
||||
@ -1234,21 +1236,41 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public virtual void ToSqlWhere(StringBuilder sb)
|
||||
{
|
||||
var andTimes = 0;
|
||||
sb.Append(" \r\nWHERE ");
|
||||
if (_source.Any())
|
||||
{
|
||||
if (_tempPrimarys.Any() == false) throw new ArgumentException(CoreStrings.NoPrimaryKey_UseSetDto(_table.Type.DisplayCsharp()));
|
||||
sb.Append('(').Append(_commonUtils.WhereItems(_tempPrimarys, "", _source)).Append(')');
|
||||
andTimes++;
|
||||
}
|
||||
|
||||
if (_where.Length > 0)
|
||||
sb.Append(_source.Any() ? _where.ToString() : _where.ToString().Substring(5));
|
||||
|
||||
if (_whereGlobalFilter.Any())
|
||||
{
|
||||
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter, false);
|
||||
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table, Alias = _tableAlias }, _whereGlobalFilter.Where(a => a.Before == true), false);
|
||||
if (string.IsNullOrEmpty(globalFilterCondi) == false)
|
||||
sb.Append(" AND ").Append(globalFilterCondi);
|
||||
{
|
||||
if (andTimes > 0) sb.Append(" AND ");
|
||||
sb.Append(globalFilterCondi);
|
||||
andTimes++;
|
||||
}
|
||||
}
|
||||
|
||||
if (_where.Length > 0)
|
||||
{
|
||||
sb.Append(andTimes > 0 ? _where.ToString() : _where.ToString().Substring(5));
|
||||
andTimes++;
|
||||
}
|
||||
|
||||
if (_whereGlobalFilter.Any())
|
||||
{
|
||||
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table, Alias = _tableAlias }, _whereGlobalFilter.Where(a => a.Before == false), false);
|
||||
if (string.IsNullOrEmpty(globalFilterCondi) == false)
|
||||
{
|
||||
if (andTimes > 0) sb.Append(" AND ");
|
||||
sb.Append(globalFilterCondi);
|
||||
andTimes++;
|
||||
}
|
||||
}
|
||||
|
||||
if (_versionColumn != null)
|
||||
|
Reference in New Issue
Block a user