Example #1
0
        internal static DbExpression CompileFunctionView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode,
            IEnumerable <DbParameterReferenceExpression> parameters)
        {
            DebugCheck.NotEmpty(viewDef);
            DebugCheck.NotNull(mappingItemCollection);

            Perspective perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            var         parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;

            // Parameters have to be accessible in the body as regular scope variables, not as command parameters.
            // Hence compile view as lambda with parameters as lambda vars, then invoke the lambda specifying
            // command parameters as values of the lambda vars.
            var functionBody = CqlQuery.CompileQueryCommandLambda(
                viewDef,
                perspective,
                parserOptions,
                null /* parameters */,
                parameters.Select(pInfo => pInfo.ResultType.Variable(pInfo.ParameterName)));

            Debug.Assert(functionBody != null, "functionBody != null");
            DbExpression expr = functionBody.Invoke(parameters);

            return(expr);
        }
Example #2
0
        internal static DbCommandTree CompileView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode)
        {
            DebugCheck.NotEmpty(viewDef);
            DebugCheck.NotNull(mappingItemCollection);

            Perspective perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            var         parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;
            var expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree;

            Debug.Assert(expr != null, "Compile returned empty tree?");

            return(expr);
        }
Example #3
0
        static internal DbCommandTree CompileView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode)
        {
            Debug.Assert(!String.IsNullOrEmpty(viewDef), "!String.IsNullOrEmpty(viewDef)");
            Debug.Assert(mappingItemCollection != null, "mappingItemCollection != null");

            Perspective   perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            ParserOptions parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;
            DbCommandTree expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree;

            Debug.Assert(expr != null, "Compile returned empty tree?");

            return(expr);
        }