|
6 | 6 | using System.Data.Common; |
7 | 7 | using System.Linq; |
8 | 8 | using System.Linq.Expressions; |
| 9 | +using System.Reflection; |
9 | 10 | using System.Text; |
10 | 11 | using System.Threading.Tasks; |
11 | 12 |
|
@@ -340,15 +341,33 @@ public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember va |
340 | 341 | //foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value); |
341 | 342 | return this; |
342 | 343 | } |
343 | | - public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> binaryExpression) { |
344 | | - if (binaryExpression?.Body.NodeType == ExpressionType.Equal) { |
345 | | - _set.Append(", ").Append(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, binaryExpression, null)); |
| 344 | + public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp) { |
| 345 | + var body = exp?.Body; |
| 346 | + var nodeType = body?.NodeType; |
| 347 | + if (nodeType == ExpressionType.Equal) { |
| 348 | + _set.Append(", ").Append(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp, null)); |
346 | 349 | return this; |
347 | 350 | } |
348 | | - if (binaryExpression?.Body is BinaryExpression == false && |
349 | | - binaryExpression?.Body.NodeType != ExpressionType.Call) return this; |
| 351 | + |
| 352 | + if (nodeType == ExpressionType.MemberInit) { |
| 353 | + var initExp = body as MemberInitExpression; |
| 354 | + if (initExp.Bindings?.Count > 0) { |
| 355 | + for (var a = 0; a < initExp.Bindings.Count; a++) { |
| 356 | + var initAssignExp = (initExp.Bindings[a] as MemberAssignment); |
| 357 | + if (initAssignExp == null) continue; |
| 358 | + var memberName = initExp.Bindings[a].Member.Name; |
| 359 | + if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue; |
| 360 | + if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}"); |
| 361 | + var memberValue = _commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, initAssignExp.Expression, null); |
| 362 | + _setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue); |
| 363 | + } |
| 364 | + } |
| 365 | + return this; |
| 366 | + } |
| 367 | + if (body is BinaryExpression == false && |
| 368 | + nodeType != ExpressionType.Call) return this; |
350 | 369 | var cols = new List<SelectColumnInfo>(); |
351 | | - var expt = _commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, cols, binaryExpression, null); |
| 370 | + var expt = _commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, cols, exp, null); |
352 | 371 | if (cols.Any() == false) return this; |
353 | 372 | foreach (var col in cols) { |
354 | 373 | if (col.Column.Attribute.IsNullable == true && col.Column.Attribute.MapType.IsNullableType()) { |
|
0 commit comments