public LambdaResolver(FluentSqlQueryBuilder sqlQueryBuilder, string tableAlias) { _sqlQueryBuilder = sqlQueryBuilder; _sqlQueryBuilder.DefineTableNameAliasOverride(tableAlias); _lambdaResolverExtension = new LambdaResolverExtension(sqlQueryBuilder); }
private Node ResolveQuery(MemberExpression memberExpression, MemberExpression rootExpression = null) { var rootExpressionToUse = rootExpression; if (rootExpressionToUse == null) { rootExpressionToUse = memberExpression; } switch (memberExpression.Expression.NodeType) { case ExpressionType.Parameter: var tableName = LambdaResolverExtension.GetTableName(rootExpressionToUse); var columnName = SqlBuilderFluentHelper.GetColumnName(rootExpressionToUse); var memberNode = new MemberNode(tableName, columnName); return(memberNode); case ExpressionType.MemberAccess: var memberExpressionExpression = memberExpression.Expression as MemberExpression; var nodeQuery = ResolveQuery(memberExpressionExpression, rootExpressionToUse); return(nodeQuery); case ExpressionType.Call: case ExpressionType.Constant: var value = _lambdaResolverExtension.GetExpressionValue(rootExpressionToUse); var valueNode = new ValueNode(value); return(valueNode); default: throw new SqlBuilderException("Expected member expression"); } }
public void AddJoinByType <TTableLeft, TTableRight>(Expression <Func <TTableLeft, TTableRight, bool> > expression, JoinType joinType, string tableAlias = null) { var joinExpression = LambdaResolverExtension.GetBinaryExpression(expression.Body); var leftMemberExpression = _lambdaResolverExtension.GetMemberExpression(joinExpression.Left); var rightMemberExpression = _lambdaResolverExtension.GetMemberExpression(joinExpression.Right); var tableSchemaName = SqlBuilderFluentHelper.GetSchema(typeof(TTableRight)); var tableName = SqlBuilderFluentHelper.GetTableName <TTableLeft>(); var tableNameToJoin = SqlBuilderFluentHelper.GetTableName <TTableRight>(); var columnNameLeft = SqlBuilderFluentHelper.GetColumnName(leftMemberExpression); var columnNameRight = SqlBuilderFluentHelper.GetColumnName(rightMemberExpression); _sqlQueryBuilder.AddJoinByType(tableSchemaName, tableName, tableNameToJoin, columnNameLeft, columnNameRight, joinType, tableAlias); }
private Node ResolveQuery(MethodCallExpression callExpression) { var functionParsed = Enum.TryParse(callExpression.Method.Name, true, out LikeMethod callFunction); if (functionParsed) { var memberExpression = callExpression.Object as MemberExpression; var argumentFunction = callExpression.Arguments.First(); var columnValue = (string)_lambdaResolverExtension.GetExpressionValue(argumentFunction); var tableName = LambdaResolverExtension.GetTableName(memberExpression); var columnName = SqlBuilderFluentHelper.GetColumnName(callExpression.Object); var memberNode = new MemberNode(tableName, columnName); var likeNode = new LikeNode(callFunction, memberNode, columnValue); return(likeNode); } else { var value = _lambdaResolverExtension.ResolveMethodCall(callExpression); var valueNode = new ValueNode(value); return(valueNode); } }