Beispiel #1
0
        private static MethodCallExpression CountExpression(ParameterExpression sourceParameter)
        {
            Type       itemType        = OeExpressionHelper.GetCollectionItemType(sourceParameter.Type);
            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(itemType);

            return(Expression.Call(countMethodInfo, sourceParameter));
        }
Beispiel #2
0
        private static MethodCallExpression CountDistinctExpression(ParameterExpression sourceParameter, LambdaExpression lambda)
        {
            MethodInfo           selectMetodInfo = OeMethodInfoHelper.GetSelectMethodInfo(lambda.Parameters[0].Type, lambda.ReturnType);
            MethodCallExpression selectCall      = Expression.Call(selectMetodInfo, sourceParameter, lambda);

            MethodInfo           distinctMethodInfo = OeMethodInfoHelper.GetDistinctMethodInfo(lambda.ReturnType);
            MethodCallExpression distinctCall       = Expression.Call(distinctMethodInfo, selectCall);

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(lambda.ReturnType);

            return(Expression.Call(countMethodInfo, distinctCall));
        }
        internal MethodCallExpression BuildExpandCount(Expression outer, Expression inner, OeNavigationSelectItem navigationItem)
        {
            IEdmNavigationProperty navigationProperty = navigationItem.EdmProperty;

            if (navigationItem.EdmProperty.ContainsTarget)
            {
                throw new InvalidOperationException("Expand cout for many-tomany not supported");
            }

            Type outerType = OeExpressionHelper.GetCollectionItemType(outer.Type);
            Type innerType = OeExpressionHelper.GetCollectionItemType(inner.Type);

            ParameterExpression outerParameter = Expression.Parameter(outerType, outerType.Name);
            IReadOnlyList <IEdmNavigationProperty> joinPath = navigationItem.Parent == null?Array.Empty <IEdmNavigationProperty>() : navigationItem.Parent.GetJoinPath();

            Expression?joinPropertyExpression = _expressionBuilder.JoinBuilder.GetJoinPropertyExpression(outerParameter, joinPath);

            if (joinPropertyExpression == null)
            {
                throw new InvalidOperationException("Outer source not found");
            }

            MethodCallExpression subquery = CreateWhereExpression(joinPropertyExpression, inner, navigationProperty);

            MethodInfo methodInfo = OeMethodInfoHelper.GetCountMethodInfo(innerType);

            subquery = Expression.Call(methodInfo, subquery);

            List <Expression> expressions = new List <Expression>();

            if (OeExpressionHelper.IsTupleType(outerParameter.Type))
            {
                expressions.AddRange(OeExpressionHelper.GetPropertyExpressions(outerParameter));
            }
            else
            {
                expressions.Add(outerParameter);
            }
            expressions.Add(OeExpressionHelper.CreateTupleExpression(new[] { subquery }));
            NewExpression newTuple = OeExpressionHelper.CreateTupleExpression(expressions);

            methodInfo = OeMethodInfoHelper.GetSelectMethodInfo(outerType, newTuple.Type);
            return(Expression.Call(methodInfo, outer, Expression.Lambda(newTuple, outerParameter)));
        }