protected override Expression VisitMemberAccess(MemberExpression memberExpression)
            {
                TableFindResult result = this.tableFinder.Find(memberExpression);

                if (this.table == null)
                {
                    this.table = result;
                }
                else if (Table != result.Table || result.MimeType != this.table.MimeType)
                {
                    Fallback = true;
                    return(memberExpression);
                }

                ContentResolverColumnMapping cmap = this.tableFinder.GetColumn(memberExpression.Member);

                if (cmap == null || cmap.Columns == null)
                {
                    Fallback = true;
                    return(memberExpression);
                }

                this.currentMap = cmap;

                if (cmap.Columns.Length == 1)
                {
                    this.builder.Append(cmap.Columns[0]);
                }
                else
                {
                    throw new NotSupportedException();
                }

                return(base.VisitMemberAccess(memberExpression));
            }
        //		private Expression VisitSelect (MethodCallExpression methodCall)
        //		{
        //			List<MemberExpression> mes = MemberExpressionFinder.Find (methodCall.Arguments[1], this.tableFinder);
        //			if (!TryGetTable (mes))
        //				return methodCall;
        //
        //			Type returnType = null;
        //
        //			List<Tuple<string, Type>> projs = new List<Tuple<string, Type>>();
        //			foreach (MemberExpression me in mes)
        //			{
        //				Tuple<string, Type> column = this.tableFinder.GetColumn (me.Member);
        //				if (column == null)
        //					return methodCall;
        //
        //				if (returnType == null)
        //					returnType = column.Item2;
        //				if (returnType != column.Item2)
        //					return methodCall;
        //
        //				projs.Add (column);
        //			}
        //
        //			ReturnType = returnType;
        //			this.fallback = true;
        //
        //			(this.projections ?? (this.projections = new List<Tuple<string, Type>>()))
        //				.AddRange (projs);
        //
        //			return methodCall.Arguments[0];
        //		}

        private Expression VisitSelectMany(MethodCallExpression methodCall)
        {
            List <MemberExpression> mes = MemberExpressionFinder.Find(methodCall, this.tableFinder);

            if (mes.Count > 1)
            {
                this.fallback = true;
                return(methodCall);
            }

            if (!TryGetTable(mes))
            {
                return(methodCall);
            }

            ContentResolverColumnMapping column = this.tableFinder.GetColumn(mes[0].Member);

            if (column == null || column.ReturnType.GetGenericTypeDefinition() != typeof(IEnumerable <>))
            {
                this.fallback = true;
                return(methodCall);
            }

            ReturnType = column.ReturnType.GetGenericArguments()[0];

            return(Expression.Constant(Activator.CreateInstance(typeof(Query <>).MakeGenericType(ReturnType), this.provider)));
            //return methodCall.Arguments[0];
        }
        private Expression VisitSelect(MethodCallExpression methodCall)
        {
            MemberExpression me = FindMemberExpression(methodCall.Arguments[1]);

            if (!TryGetTable(me))
            {
                return(methodCall);
            }

            ContentResolverColumnMapping column = this.tableFinder.GetColumn(me.Member);

            if (column == null || column.Columns == null)
            {
                return(methodCall);
            }

            (this.projections ?? (this.projections = new List <ContentResolverColumnMapping>())).Add(column);
            if (column.ReturnType.IsValueType || column.ReturnType == typeof(string))
            {
                ReturnType = column.ReturnType;
            }

            this.fallback = true;

            Type argType = GetExpressionArgumentType(methodCall.Arguments[0]);

            if (ReturnType == null || (argType != null && ReturnType.IsAssignableFrom(argType)))
            {
                return(methodCall.Arguments[0]);
            }

            return(Expression.Constant(Activator.CreateInstance(typeof(Query <>).MakeGenericType(ReturnType), this.provider)));
        }
        private Expression VisitOrder(MethodCallExpression methodCall)
        {
            MemberExpression me = FindMemberExpression(methodCall.Arguments[1]);

            if (!TryGetTable(me))
            {
                return(methodCall);
            }

            ContentResolverColumnMapping column = this.tableFinder.GetColumn(me.Member);

            if (column != null && column.Columns != null)
            {
                StringBuilder builder = this.sortBuilder ?? (this.sortBuilder = new StringBuilder());
                if (builder.Length > 0)
                {
                    builder.Append(", ");
                }

                if (column.Columns.Length > 1)
                {
                    throw new NotSupportedException();
                }

                builder.Append(column.Columns[0]);

                if (methodCall.Method.Name == "OrderByDescending")
                {
                    builder.Append(" DESC");
                }

                return(methodCall.Arguments[0]);
            }

            return(methodCall);
        }
      protected override Expression VisitMemberAccess(MemberExpression memberExpression)
      {
        TableFindResult result = this.tableFinder.Find(memberExpression);
        if (this.table == null)
          this.table = result;
        else if (Table != result.Table || result.MimeType != this.table.MimeType)
        {
          Fallback = true;
          return memberExpression;
        }

        ContentResolverColumnMapping cmap = this.tableFinder.GetColumn(memberExpression.Member);
        if (cmap == null || cmap.Columns == null)
        {
          Fallback = true;
          return memberExpression;
        }

        this.currentMap = cmap;

        if (cmap.Columns.Length == 1)
          this.builder.Append(cmap.Columns[0]);
        else
          throw new NotSupportedException();

        return base.VisitMemberAccess(memberExpression);
      }