예제 #1
0
        /// <summary>
        /// Creates the query for type and current expression.
        /// </summary>
        /// <typeparam name="TS">currenty type passed by frameowrk</typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        public IQueryable <TS> CreateQuery <TS>(Expression expression)
        {
            // make sure there are no previous items left in the collection.
            if ((int)this.Count() > 0)
            {
                this.Clear();
            }

            this.currentExpression = expression;
            var curentMethodcall = currentExpression as MethodCallExpression;

            if (curentMethodcall != null)
            {
                string methodName = curentMethodcall.Method.Name;
                if (methodName == MethodNames.Join)
                {
                    throw new ProviderException(Messages.DirectJoinNotSupported);
                }

                if (IsOnQueryMethodCall(curentMethodcall.Method))
                {
                    var args = new MethodCall.Parameter[curentMethodcall.Arguments.Count - 1];

                    int index = 0;

                    foreach (var arg in args)
                    {
                        var argument = curentMethodcall.Arguments[index + 1];

                        this.Visit(argument);
                        args[index] = new MethodCall.Parameter(argument.Type, this.value);

                        index++;
                    }

                    var target = (curentMethodcall.Arguments[0] as ConstantExpression).Value;
                    // just append the method here.
                    Buckets.Current.Methods.Add(new MethodCall(target, curentMethodcall.Method, args));
                }
                else
                {
                    // Create a new bucket when Query<T>.Execute is called or it is empty for current type.
                    if ((!Buckets.ContainsKey(typeof(T))) || Buckets.Current.Processed)
                    {
                        Buckets.Current = BucketImpl <T> .NewInstance.Init();
                    }

                    this.Visit(curentMethodcall);
                }
            }

            if (typeof(T) != typeof(TS))
            {
                projectedQuery = new ProjectedQuery <T, TS>(expression, this);

                return((IQueryable <TS>)projectedQuery);
            }

            return((IQueryable <TS>) this);
        }
예제 #2
0
        void IDisposable.Dispose()
        {
            // clean up expression object from memory.
            if (this.currentExpression != null)
            {
                currentExpression = null;
            }
            Buckets.Clear();

            Clear();
        }