private void MemberAccessResolve(Expression exp) { if (exp == null || !(exp is MemberExpression memberExp)) { return; } if (memberExp.Expression != null) { if (memberExp.Expression.NodeType == ExpressionType.Parameter) { _sqlBuilder.Append(_queryBody.GetColumnName(memberExp, _fullExpression)); return; } if (memberExp.Expression.NodeType == ExpressionType.Constant) { DynamicInvokeResolve(exp); return; } if (memberExp.Expression.NodeType == ExpressionType.MemberAccess) { if (memberExp.Expression is MemberExpression subMemberExp && subMemberExp.Expression.NodeType == ExpressionType.Constant) { DynamicInvokeResolve(exp); return; } //分组查询 if (_queryBody.IsGroupBy) { var descriptor = _queryBody.GroupByPropertyList.FirstOrDefault(m => m.Alias == memberExp.Member.Name); if (descriptor != null) { var colName = _queryBody.GetColumnName(descriptor.Name, descriptor.JoinDescriptor); _sqlBuilder.AppendFormat("{0}", colName); return; } } else if (memberExp.Expression.Type.IsString()) { switch (memberExp.Member.Name) { case "Length": //解析Length函数 var funcName = _sqlAdapter.FuncLength; var colName = _queryBody.GetColumnName(memberExp.Expression as MemberExpression, _fullExpression); _sqlBuilder.AppendFormat("{0}({1})", funcName, colName); return; } } } } //对于非实体属性的成员,如外部变量等 DynamicInvokeResolve(exp); }