Example #1
0
        private static TResult AnalyzeSemanticsCommon <TResult>(
            System.Data.Entity.Core.Common.EntitySql.AST.Node astExpr,
            Perspective perspective,
            ParserOptions parserOptions,
            IEnumerable <DbParameterReferenceExpression> parameters,
            IEnumerable <DbVariableReferenceExpression> variables,
            Func <SemanticAnalyzer, System.Data.Entity.Core.Common.EntitySql.AST.Node, TResult> analysisFunction)
            where TResult : class
        {
            TResult result = default(TResult);

            try
            {
                SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(SemanticResolver.Create(perspective, parserOptions, parameters, variables));
                return(analysisFunction(semanticAnalyzer, astExpr));
            }
            catch (MetadataException ex)
            {
                throw new EntitySqlException(Strings.GeneralExceptionAsQueryInnerException((object)"Metadata"), (Exception)ex);
            }
            catch (MappingException ex)
            {
                throw new EntitySqlException(Strings.GeneralExceptionAsQueryInnerException((object)"Mapping"), (Exception)ex);
            }
        }
Example #2
0
        private static TResult AnalyzeSemanticsCommon <TResult>(
            Node astExpr,
            Perspective perspective,
            ParserOptions parserOptions,
            IEnumerable <DbParameterReferenceExpression> parameters,
            IEnumerable <DbVariableReferenceExpression> variables,
            Func <SemanticAnalyzer, Node, TResult> analysisFunction)
            where TResult : class
        {
            DebugCheck.NotNull(astExpr);
            DebugCheck.NotNull(perspective);

            TResult result = null;

            try
            {
                //
                // Invoke semantic analysis
                //
                var analyzer = (new SemanticAnalyzer(SemanticResolver.Create(perspective, parserOptions, parameters, variables)));
                result = analysisFunction(analyzer, astExpr);
            }
            //
            // Wrap MetadataException as EntityException inner exception
            //
            catch (MetadataException metadataException)
            {
                var message = Strings.GeneralExceptionAsQueryInnerException("Metadata");
                throw new EntitySqlException(message, metadataException);
            }
            //
            // Wrap MappingException as EntityException inner exception
            //
            catch (MappingException mappingException)
            {
                var message = Strings.GeneralExceptionAsQueryInnerException("Mapping");
                throw new EntitySqlException(message, mappingException);
            }

            return(result);
        }