internal static DbExpression CompileFunctionView( string viewDef, StorageMappingItemCollection mappingItemCollection, ParserOptions.CompilationMode compilationMode, IEnumerable<DbParameterReferenceExpression> parameters) { Debug.Assert(!String.IsNullOrEmpty(viewDef), "!String.IsNullOrEmpty(viewDef)"); Debug.Assert(mappingItemCollection != null, "mappingItemCollection != null"); 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; }
internal static 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); 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; }