public FetchExpressionNodeBase (MethodCallExpressionParseInfo parseInfo, LambdaExpression relatedObjectSelector)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("relatedObjectSelector", relatedObjectSelector);

      var memberExpression = relatedObjectSelector.Body as MemberExpression;
      if (memberExpression == null)
      {
        var message = string.Format (
            "A fetch request must be a simple member access expression; '{0}' is a {1} instead.",
            relatedObjectSelector.Body,
            relatedObjectSelector.Body.GetType ().Name);
        throw new ArgumentException (message, "relatedObjectSelector");
      }

      if (memberExpression.Expression.NodeType != ExpressionType.Parameter)
      {
        var message = string.Format (
            "A fetch request must be a simple member access expression of the kind o => o.Related; '{0}' is too complex.",
            relatedObjectSelector.Body);
        throw new ArgumentException (message, "relatedObjectSelector");
      }

      RelationMember = memberExpression.Member;
    }
    public GroupJoinExpressionNode (
        MethodCallExpressionParseInfo parseInfo, 
        Expression innerSequence,
        LambdaExpression outerKeySelector,
        LambdaExpression innerKeySelector,
        LambdaExpression resultSelector)
        : base(parseInfo)
    {
      ArgumentUtility.CheckNotNull ("innerSequence", innerSequence);
      ArgumentUtility.CheckNotNull ("outerKeySelector", outerKeySelector);
      ArgumentUtility.CheckNotNull ("innerKeySelector", innerKeySelector);
      ArgumentUtility.CheckNotNull ("resultSelector", resultSelector);

      if (outerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Outer key selector must have exactly one parameter.", "outerKeySelector");
      if (innerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Inner key selector must have exactly one parameter.", "innerKeySelector");
      if (resultSelector.Parameters.Count != 2)
        throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

      var joinResultSelector = Expression.Lambda (Expression.Constant (null), outerKeySelector.Parameters[0], innerKeySelector.Parameters[0]);
      JoinExpressionNode = new JoinExpressionNode (parseInfo, innerSequence, outerKeySelector, innerKeySelector, joinResultSelector);
      
      ResultSelector = resultSelector;
      _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
    }
 public QueryAnnotationExpressionNode(
     MethodCallExpressionParseInfo parseInfo,
     [NotNull] ConstantExpression annotationExpression)
     : base(parseInfo, null, null)
 {
     _annotationExpression = annotationExpression;
 }
        public JoinExpressionNode(
        MethodCallExpressionParseInfo parseInfo,
        Expression innerSequence,
        LambdaExpression outerKeySelector,
        LambdaExpression innerKeySelector,
        LambdaExpression resultSelector)
            : base(parseInfo)
        {
            ArgumentUtility.CheckNotNull ("innerSequence", innerSequence);
              ArgumentUtility.CheckNotNull ("outerKeySelector", outerKeySelector);
              ArgumentUtility.CheckNotNull ("innerKeySelector", innerKeySelector);
              ArgumentUtility.CheckNotNull ("resultSelector", resultSelector);

              if (outerKeySelector.Parameters.Count != 1)
            throw new ArgumentException ("Outer key selector must have exactly one parameter.", "outerKeySelector");
              if (innerKeySelector.Parameters.Count != 1)
            throw new ArgumentException ("Inner key selector must have exactly one parameter.", "innerKeySelector");
              if (resultSelector.Parameters.Count != 2)
            throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

              InnerSequence = innerSequence;
              OuterKeySelector = outerKeySelector;
              InnerKeySelector = innerKeySelector;
              ResultSelector = resultSelector;

              _cachedOuterKeySelector = new ResolvedExpressionCache<Expression> (this);
              _cachedInnerKeySelector = new ResolvedExpressionCache<Expression> (this);
              _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
        }
        /// <summary>
        /// Creates an instace of type <paramref name="nodeType"/>.
        /// </summary>
        /// <exception cref="ExpressionNodeInstantiationException">
        /// Thrown if the <paramref name="parseInfo"/> or the <paramref name="additionalConstructorParameters"/> 
        /// do not match expected constructor parameters of the <paramref name="nodeType"/>.
        /// </exception>
        public static IExpressionNode CreateExpressionNode(
        Type nodeType, MethodCallExpressionParseInfo parseInfo, object[] additionalConstructorParameters)
        {
            ArgumentUtility.CheckNotNull ("nodeType", nodeType);
              ArgumentUtility.CheckTypeIsAssignableFrom ("nodeType", nodeType, typeof (IExpressionNode));
              ArgumentUtility.CheckNotNull ("additionalConstructorParameters", additionalConstructorParameters);

            #if NETFX_CORE
              var constructors = nodeType.GetTypeInfo().DeclaredConstructors.Where (c => c.IsPublic).ToArray();
            #else
              var constructors = nodeType.GetTypeInfo().GetConstructors().Where (c => c.IsPublic).ToArray();
            #endif
              if (constructors.Length > 1)
              {
            var message = string.Format (
            "Expression node type '{0}' contains too many constructors. It must only contain a single constructor, allowing null to be passed for any optional arguments.",
            nodeType.FullName);
            throw new ArgumentException (message, "nodeType");
              }

              object[] constructorParameterArray = GetParameterArray (constructors[0], parseInfo, additionalConstructorParameters);
              try
              {
            return (IExpressionNode) constructors[0].Invoke (constructorParameterArray);
              }
              catch (ArgumentException ex)
              {
            var message = GetArgumentMismatchMessage (ex);
            throw new ExpressionNodeInstantiationException (message);
              }
        }
 protected QuerySourceSetOperationExpressionNodeBase (MethodCallExpressionParseInfo parseInfo, Expression source2)
     : base (parseInfo, null, null)
 {
   ArgumentUtility.CheckNotNull ("source2", source2);
   _source2 = source2;
   _itemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (parseInfo.ParsedExpression.Type, "expression");
 }
Example #7
0
 public UnionExpressionNode (MethodCallExpressionParseInfo parseInfo, Expression source2)
   : base (parseInfo, null, null)
 {
   ArgumentUtility.CheckNotNull ("source2", source2);
   Source2 = source2;
   ItemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (parseInfo.ParsedExpression.Type, "expression");
 }
    public override void SetUp ()
    {
      base.SetUp();

      _keySelector = ExpressionHelper.CreateLambdaExpression<int, short> (i => (short) i);
      _elementSelector = ExpressionHelper.CreateLambdaExpression<int, string> (i => i.ToString());
      _resultSelectorWithElementSelector = 
          ExpressionHelper.CreateLambdaExpression<short, IEnumerable<string>, Tuple<short, int>> ((key, group) => Tuple.Create (key, group.Count()));

      _sourceEnumerable = ExpressionHelper.CreateIntQueryable();

      var methodCallExpressionWithElementSelector = (MethodCallExpression) ExpressionHelper.MakeExpression (
          () => _sourceEnumerable.GroupBy (
              i => (short) i,
              i => i.ToString(),
              (key, group) => Tuple.Create (key, group.Count())));
      _parseInfoWithElementSelector = new MethodCallExpressionParseInfo ("g", SourceNode, methodCallExpressionWithElementSelector);
      _nodeWithElementSelector = new GroupByWithResultSelectorExpressionNode (
          _parseInfoWithElementSelector,
          _keySelector,
          _elementSelector,
          _resultSelectorWithElementSelector);

      var methodCallExpressionWithoutElementSelector = (MethodCallExpression) ExpressionHelper.MakeExpression (
          () => _sourceEnumerable.GroupBy (
              i => (short) i,
              (key, group) => Tuple.Create (key, group.Count())));
      _resultSelectorWithoutElementSelector = 
          ExpressionHelper.CreateLambdaExpression<short, IEnumerable<int>, Tuple<short, int>> ((key, group) => Tuple.Create (key, group.Count()));
      _nodeWithoutElementSelector = new GroupByWithResultSelectorExpressionNode (
          new MethodCallExpressionParseInfo ("g", SourceNode, methodCallExpressionWithoutElementSelector),
          _keySelector,
          _resultSelectorWithoutElementSelector,
          null);
    }
 public ThenIncludeExpressionNode(
     MethodCallExpressionParseInfo parseInfo,
     [NotNull] LambdaExpression navigationPropertyPathLambda)
     : base(parseInfo, null, null)
 {
     _navigationPropertyPathLambda = navigationPropertyPathLambda;
 }
    public SelectManyExpressionNode (
        MethodCallExpressionParseInfo parseInfo, LambdaExpression collectionSelector, LambdaExpression resultSelector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("collectionSelector", collectionSelector);

      if (collectionSelector.Parameters.Count != 1)
        throw new ArgumentException ("Collection selector must have exactly one parameter.", "collectionSelector");

      CollectionSelector = collectionSelector;

      if (resultSelector != null)
      {
        if (resultSelector.Parameters.Count != 2)
          throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

        ResultSelector = resultSelector;
      }
      else
      {
        var parameter1 = Expression.Parameter (collectionSelector.Parameters[0].Type, collectionSelector.Parameters[0].Name);
        var itemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (CollectionSelector.Body.Type, "collectionSelector");
        var parameter2 = Expression.Parameter (itemType, parseInfo.AssociatedIdentifier);
        ResultSelector = Expression.Lambda (parameter2, parameter1, parameter2);
      }

      _cachedCollectionSelector = new ResolvedExpressionCache<Expression> (this);
      _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
    }
Example #11
0
    public AllExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression predicate)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("predicate", predicate);

      _predicate = predicate;
      _cachedPredicate = new ResolvedExpressionCache<Expression> (this);
    }
        public IncludeExpressionNode(
            MethodCallExpressionParseInfo parseInfo,
            [NotNull] LambdaExpression navigationPropertyPathLambda)
            : base(parseInfo, null, null)
        {
            Check.NotNull(navigationPropertyPathLambda, nameof(navigationPropertyPathLambda));

            _navigationPropertyPathLambda = navigationPropertyPathLambda;
        }
 public FromSqlExpressionNode(
     MethodCallExpressionParseInfo parseInfo,
     [NotNull] ConstantExpression sql,
     [NotNull] Expression arguments)
     : base(parseInfo, null, null)
 {
     _sql = (string)sql.Value;
     _arguments = arguments;
 }
        public WhereMissingExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression predicate)
            : base(parseInfo)
        {
            if (predicate.Parameters.Count != 1)
                throw new ArgumentException("Predicate must have exactly one parameter.", "predicate");

            Predicate = predicate;
            _cachedPredicate = new ResolvedExpressionCache<Expression>(this);
        }
    protected MethodCallExpressionNodeBase (MethodCallExpressionParseInfo parseInfo)
    {
      if (parseInfo.AssociatedIdentifier == null)
        throw new ArgumentException ("Unitialized struct.", "parseInfo");

      _associatedIdentifier = parseInfo.AssociatedIdentifier;
      _source = parseInfo.Source;
      _nodeResultType = parseInfo.ParsedExpression.Type;
    }
 public IncludeExpressionNode(
     MethodCallExpressionParseInfo parseInfo, LambdaExpression idSource, LambdaExpression callback,
     ConstantExpression joinType)
     : base(parseInfo, null, null)
 {
     IdSource = idSource;
     Callback = callback;
     JoinType = joinType;
 }
        public UseKeysExpressionNode(MethodCallExpressionParseInfo parseInfo, Expression keys)
            : base(parseInfo)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }

            Keys = keys;
        }
    public static SelectManyExpressionNode CreateSelectMany (IExpressionNode source)
    {
      var p1 = Expression.Parameter (typeof (Cook), "s");
      var p2 = Expression.Parameter (typeof (Kitchen), "sd");
      var resultSelector = Expression.Lambda (Expression.Constant (null), p1, p2);
      var collectionSelector = Expression.Lambda (Expression.Constant (null), p1);

      var parseInfo = new MethodCallExpressionParseInfo ("trans", source, ExpressionHelper.CreateMethodCallExpression<Cook> ());
      return new SelectManyExpressionNode (parseInfo, collectionSelector, resultSelector);
    }
 private IExpressionNode CreateExpressionNode(Type nodeType, MethodCallExpressionParseInfo parseInfo, object[] additionalConstructorParameters)
 {
     try
       {
     return MethodCallExpressionNodeFactory.CreateExpressionNode (nodeType, parseInfo, additionalConstructorParameters);
       }
       catch (ExpressionNodeInstantiationException ex)
       {
     throw CreateParsingErrorException (parseInfo.ParsedExpression, "{0}", ex.Message);
       }
 }
    public IExpressionNode Parse (
        string associatedIdentifier, IExpressionNode source, IEnumerable<Expression> arguments, MethodCallExpression expressionToParse)
    {
      ArgumentUtility.CheckNotNull ("expressionToParse", expressionToParse);

      Type nodeType = GetNodeType (expressionToParse);
      var additionalConstructorParameters = arguments.Select (expr => ProcessArgumentExpression (expr)).ToArray();

      var parseInfo = new MethodCallExpressionParseInfo (associatedIdentifier, source, expressionToParse);
      return CreateExpressionNode (nodeType, parseInfo, additionalConstructorParameters);
    }
    public ThenByExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);

      if (keySelector.Parameters.Count != 1)
        throw new ArgumentException ("KeySelector must have exactly one parameter.", "keySelector");

      KeySelector = keySelector;
      _cachedSelector = new ResolvedExpressionCache<Expression> (this);
    }
    public AggregateExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression func)
        : base(parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("func", func);

      if (func.Parameters.Count != 2)
        throw new ArgumentException ("Func must have exactly two parameters.", "func");

      _func = func;
      _cachedFunc = new ResolvedExpressionCache<LambdaExpression> (this);
    }
    protected ResultOperatorExpressionNodeBase (
        MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate, LambdaExpression optionalSelector)
        : base (TransformParseInfo (parseInfo, optionalPredicate, optionalSelector))
    {
      if (optionalPredicate != null && optionalPredicate.Parameters.Count != 1)
        throw new ArgumentException ("OptionalPredicate must have exactly one parameter.", "optionalPredicate");

      if (optionalSelector != null && optionalSelector.Parameters.Count != 1)
        throw new ArgumentException ("OptionalSelector must have exactly one parameter.", "optionalSelector");

      _parsedExpression = parseInfo.ParsedExpression;
    }
        public QueryAnnotationExpressionNode(
            MethodCallExpressionParseInfo parseInfo,
            [NotNull] ConstantExpression annotationExpression)
            : base(
                Check.NotNull(parseInfo, nameof(parseInfo)),
                null,
                null)
        {
            Check.NotNull(annotationExpression, nameof(annotationExpression));

            _annotationExpression = annotationExpression;
        }
    public GroupByWithResultSelectorExpressionNode (
        MethodCallExpressionParseInfo parseInfo, 
        LambdaExpression keySelector, 
        LambdaExpression elementSelectorOrResultSelector, 
        LambdaExpression resultSelectorOrNull)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);
      ArgumentUtility.CheckNotNull ("elementSelectorOrResultSelector", elementSelectorOrResultSelector);

      _selectExpressionNode = new SelectExpressionNode (
          CreateParseInfoWithGroupNode (parseInfo, keySelector, elementSelectorOrResultSelector, resultSelectorOrNull),
          CreateSelectorForSelectNode (keySelector, elementSelectorOrResultSelector, resultSelectorOrNull));
    }
        public FetchExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression selector)
            : base(parseInfo, null, null)
        {
            ArgumentUtility.CheckNotNull("selector", selector);

            if (selector.Parameters.Count != 1)
            {
                throw new ArgumentException("Selector must have exactly one parameter", "selector");
            }

            Selector = selector;
            _cachedSelector = new ResolvedExpressionCache<Expression>(this);
        }
    private static MethodCallExpressionParseInfo TransformParseInfo (
        MethodCallExpressionParseInfo parseInfo,
        LambdaExpression optionalPredicate,
        LambdaExpression optionalSelector)
    {
      var source = parseInfo.Source;

      if (optionalPredicate != null)
        source = new WhereExpressionNode (parseInfo, optionalPredicate);

      if (optionalSelector != null)
      {
        var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
        source = new SelectExpressionNode (newParseInfo, optionalSelector);
      }

      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
    }
    private static object[] GetParameterArray (
        ConstructorInfo nodeTypeConstructor, MethodCallExpressionParseInfo parseInfo, object[] additionalConstructorParameters)
    {
      var parameterInfos = nodeTypeConstructor.GetParameters();
      if (additionalConstructorParameters.Length > parameterInfos.Length - 1)
      {
        string message = string.Format (
            "The constructor of expression node type '{0}' only takes {1} parameters, but you specified {2} (including the parse info parameter).",
            nodeTypeConstructor.DeclaringType.FullName,
            parameterInfos.Length,
            additionalConstructorParameters.Length + 1);
        throw new ExpressionNodeInstantiationException (message);
      }

      var constructorParameters = new object[parameterInfos.Length];
      constructorParameters[0] = parseInfo;
      additionalConstructorParameters.CopyTo (constructorParameters, 1);
      return constructorParameters;
    }
    public GroupByExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector, LambdaExpression optionalElementSelector)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);

      if (keySelector.Parameters.Count != 1)
        throw new ArgumentException ("KeySelector must have exactly one parameter.", "keySelector");

      if (optionalElementSelector != null && optionalElementSelector.Parameters.Count != 1)
        throw new ArgumentException ("ElementSelector must have exactly one parameter.", "optionalElementSelector");

      _keySelector = keySelector;
      _optionalElementSelector = optionalElementSelector;

      _cachedKeySelector = new ResolvedExpressionCache<Expression> (this);

      if (optionalElementSelector != null)
        _cachedElementSelector = new ResolvedExpressionCache<Expression> (this);
    }
        public UseIndexExpressionNode(MethodCallExpressionParseInfo parseInfo, ConstantExpression indexName, ConstantExpression indexType)
            : base(parseInfo)
        {
            if (indexName == null)
            {
                throw new ArgumentNullException("indexName");
            }
            if (indexName.Type != typeof(string))
            {
                throw new ArgumentException("indexName must return a string", "indexName");
            }

            if (indexType.Type != typeof(N1QlIndexType))
            {
                throw new ArgumentException("indexType must return a N1QlIndexType", "indexType");
            }

            IndexName = indexName;
            IndexType = indexType;
        }