예제 #1
0
        public TransformVisitor(ITypeConverter converter)
        {
            this.converter        = converter;
            this.edmTypeConverter = new EdmTypeConverter(converter);

            this.queryMethodExpressionBuilder = new LinqMethodExpressionBuilder();
            this.currentVariables             = new VariableCollection();
            this.parameters = new Dictionary <string, Tuple <TypeUsage, int> >();

            this.functionMapper = new CanonicalFunctionMapper(converter);
            this.methodProvider = new Effort.Internal.DbManagement.DbMethodProvider();
        }
예제 #2
0
        public static Expression GetEnumeratorExpression(
            DbExpression predicate,
            DbModificationCommandTree commandTree,
            DbContainer container,
            out ITable table)
        {
            TransformVisitor visitor = new TransformVisitor(container.TypeConverter);
            visitor.TableProvider = container;

            // Get the source expression
            ConstantExpression source =
                visitor.Visit(commandTree.Target.Expression) as ConstantExpression;

            // This should be a constant expression
            if (source == null)
            {
                throw new InvalidOperationException();
            }

            table = source.Value as ITable;

            // Get the the type of the elements of the table
            Type elementType = TypeHelper.GetElementType(source.Type);

            // Create context
            ParameterExpression context = Expression.Parameter(elementType, "context");
            using (visitor.CreateVariable(context, commandTree.Target.VariableName))
            {
                // Create the predicate expression
                LambdaExpression predicateExpression =
                    Expression.Lambda(
                        visitor.Visit(predicate),
                        context);

                // Create Where expression
                LinqMethodExpressionBuilder queryMethodBuilder =
                    new LinqMethodExpressionBuilder();

                return queryMethodBuilder.Where(source, predicateExpression);
            }
        }