Skip to content

Commit b2f484d

Browse files
committed
- 优化 UpdateJoin .Set 固定值解析;
1 parent 561b103 commit b2f484d

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Examples/base_entity/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ static void Main(string[] args)
586586
.Join<UserGroup>((a, b) => a.GroupId == b.Id)
587587
.Set((a, b) => a.Nickname == b.GroupName)
588588
.ExecuteAffrows();
589+
var updatejoin03 = fsql.Update<User1>()
590+
.Join<UserGroup>((a, b) => a.GroupId == b.Id)
591+
.Set((a, b) => a.Nickname == "b.groupname")
592+
.ExecuteAffrows();
589593

590594
var sql1c2 = fsql.Select<User1>()
591595
.GroupBy(a => new { a.Nickname, a.Avatar })

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,23 @@ public IUpdateJoin<T1, T2> SetIf(bool condition, Expression<Func<T1, T2, bool>>
169169
if (cols.Count != 1) return this;
170170
var col = cols[0].Column;
171171
var columnSql = $"{_commonUtils.QuoteSqlName(col.Attribute.Name)}";
172+
var valueSql = "";
172173

173-
_query2Provider._groupby = null;
174-
var valueExp = Expression.Lambda<Func<T1, T2, object>>(equalBinaryExp.Right, exp.Parameters);
175-
_query2.GroupBy(valueExp);
176-
var valueSql = _query2Provider._groupby?.Remove(0, " \r\nGROUP BY ".Length);
174+
if (equalBinaryExp.Right.IsParameter())
175+
{
176+
_query2Provider._groupby = null;
177+
var valueExp = Expression.Lambda<Func<T1, T2, object>>(equalBinaryExp.Right, exp.Parameters);
178+
_query2.GroupBy(valueExp);
179+
valueSql = _query2Provider._groupby?.Remove(0, " \r\nGROUP BY ".Length);
180+
}
181+
else
182+
{
183+
valueSql = _commonExpression.ExpressionLambdaToSql(equalBinaryExp.Right, new CommonExpression.ExpTSC
184+
{
185+
isQuoteName = true,
186+
mapType = equalBinaryExp.Right is BinaryExpression ? null : col.Attribute.MapType
187+
});
188+
}
177189
if (string.IsNullOrEmpty(valueSql)) return this;
178190

179191
switch (_orm.Ado.DataType)

0 commit comments

Comments
 (0)