/// <summary> /// 根据指定表达式取表别名 /// </summary> /// <param name="expression">表达式</param> /// <remarks> /// t=>t.Id /// t.Id /// </remarks> public string GetTableAlias(Expression expression) { // p=>p.p // p=>p.Id // p=>p.t.Id // p.Id // p.t.Id // p.t // <>h__TransparentIdentifier0.p.Id XFrameworkException.Check.NotNull(expression, "expression"); string key = TableAlias.GetTableAliasKey(expression); return(this.GetTableAlias(key)); }
private static string GetTableAliasKey(Expression exp) { if (exp == null) { return(null); } Expression expression = exp.ReduceUnary(); //c if (exp.CanEvaluate()) { return(null); } // p var parameter = expression as ParameterExpression; if (parameter != null) { return(parameter.Name); } // a=>a.Id var lambda = expression as LambdaExpression; if (lambda != null) { expression = lambda.Body.ReduceUnary(); } // a.Id // t.a // t.t.a // t.a.Id var member = expression as MemberExpression; if (member == null) { return(TableAlias.GetTableAliasKey(expression)); } if (member.Visitable()) { return(TableAlias.GetTableAliasKey(member.Expression)); } return(member.Member.Name); }