public static Expression BuildAndConvert(Expression expression, DbCommandBuilder builder, IServiceProvider serviceProvider, bool isJson)
        {
            var visitor = new RoscoeExpressionVisitor(builder, serviceProvider, Expression.Parameter(typeof(JValue)));
            var result  = visitor.Visit(expression);

            serviceProvider.GetRequiredService <IRoscoeExpressionValueFactory>()
            .Create(visitor.columns, isJson)
            .Build(builder, serviceProvider);

            return(result);
        }
        public static Expression <Func <JToken, T> > BuildAndConvert <T>(Expression <Func <T> > expression, DbCommandBuilder builder, IServiceProvider serviceProvider, bool isJson)
        {
            var parameter = Expression.Parameter(typeof(JToken));
            var visitor   = new RoscoeExpressionVisitor(builder, serviceProvider, parameter);

            if (visitor.Visit(expression) is Expression <Func <T> > result)
            {
                serviceProvider.GetRequiredService <IRoscoeExpressionValueFactory>()
                .Create(visitor.columns, isJson)
                .Build(builder, serviceProvider);

                return(Expression.Lambda <Func <JToken, T> >(result.Body, parameter));
            }

            throw new Exception("Could not convert expression");
        }
Esempio n. 3
0
        public void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
        {
            if (Expression != null)
            {
                var environmentOption = serviceProvider.GetRequiredService <EnvironmentOption>();

                builder.SqlBuilder.Write("select ");

                var aliasOption    = serviceProvider.GetRequiredService <AliasOption>();
                var oldAliasOption = aliasOption.Clone();
                aliasOption.EmitWithAlias = true;
                aliasOption.EmitTable     = true;

                ConvertExpression = RoscoeExpressionVisitor.BuildAndConvert(Expression, builder, serviceProvider, !environmentOption.IsSubQuery);

                builder.SqlBuilder.WriteLine();

                aliasOption.Restore(oldAliasOption);
            }
        }