Exemplo n.º 1
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var expr    = builder.Arguments[0];
                var newExpr = expr.Transform(e =>
                {
                    if (e.NodeType == ExpressionType.Convert || e.NodeType == ExpressionType.ConvertChecked)
                    {
                        var unary  = (UnaryExpression)e;
                        var method = _method.MakeGenericMethod(unary.Operand.Type, unary.Type);
                        return(Expression.Call(null, method, unary.Operand));
                    }
                    return(e);
                });

                if (newExpr == expr)
                {
                    builder.ResultExpression = builder.GetExpression(0);
                    return;
                }

                var sqlExpr = builder.ConvertExpressionToSql(newExpr);

                sqlExpr = new QueryVisitor().Convert(sqlExpr, e =>
                {
                    if (e is SqlFunction func && func.Name == "$Convert_Remover$")
                    {
                        return(func.Parameters[0]);
                    }
                    return(e);
                });
Exemplo n.º 2
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var pathExpr = builder.Arguments[0];

                if (pathExpr.NodeType != ExpressionType.MemberAccess)
                {
                    throw new NotSupportedException();
                }

                var pathList = new List <Expression>();
                var current  = pathExpr;

                while (true)
                {
                    pathList.Add(current);
                    if (current.NodeType == ExpressionType.MemberAccess)
                    {
                        current = ((MemberExpression)current).Expression;
                    }
                    else
                    {
                        break;
                    }
                }

                pathList.Reverse();

                var entity = pathList[0];
                var field  = pathList[1];

                var fieldSql = builder.ConvertExpressionToSql(field);

                builder.AddParameter("field", fieldSql);

                var propPathStr = "$";

                for (int i = 2; i < pathList.Count; i++)
                {
                    propPathStr += "." + ((MemberExpression)pathList[i]).Member.Name;
                }

                builder.AddParameter("propPath", new SqlValue(propPathStr));
            }