Esempio n. 1
0
        private BinaryOperatorNode BuildFilterExpression(SingleResourceNode source, GraphQLFieldSelection selection)
        {
            BinaryOperatorNode compositeNode = null;
            IEdmEntityType     entityType    = source.NavigationSource.EntityType();

            foreach (GraphQLArgument argument in selection.Arguments)
            {
                IEdmProperty edmProperty = FindEdmProperty(entityType, argument.Name.Value);
                var          left        = new SingleValuePropertyAccessNode(source, edmProperty);

                Object value = GetArgumentValue(edmProperty.Type, argument.Value);
                var    right = new ConstantNode(value, ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V4));
                var    node  = new BinaryOperatorNode(BinaryOperatorKind.Equal, left, right);
                compositeNode = ComposeExpression(compositeNode, node);
            }

            //foreach (ASTNode astNode in selection.SelectionSet.Selections)
            //    if (astNode is GraphQLFieldSelection fieldSelection && fieldSelection.SelectionSet != null)
            //    {
            //        var navigationProperty = (IEdmNavigationProperty)FindEdmProperty(entityType, fieldSelection.Name.Value);
            //        if (navigationProperty.Type is IEdmCollectionTypeReference)
            //            continue;

            //        var parentSource = new SingleNavigationNode(source, navigationProperty, null);
            //        BinaryOperatorNode node = BuildFilterExpression(parentSource, fieldSelection);
            //        compositeNode = ComposeExpression(compositeNode, node);
            //    }

            return(compositeNode);
        }
        private void TestCast <TParam, TReturn>(SingleResourceNode source, IEdmEntityType cast, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            var node   = new SingleResourceCastNode(source, cast);
            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
        public void TranslatorShouldConvertWeaklyBackedSingleEntityCast()
        {
            SingleResourceNode source = EntityParameter <Customer>("c");
            QueryNode          node   = new SingleResourceCastNode(source, this.weaklyBackedCustomerEdmType);
            var result = this.testSubject.TranslateNode(node);

            var parameterExpression = Expression.Parameter(typeof(Customer), "c");
            var expected            = Expression.Call(typeof(DataServiceProviderMethods), "TypeAs", new[] { typeof(object) }, parameterExpression, Expression.Constant(this.weaklyBackedDerivedType));

            CompareExpressions(expected, result);
        }
        private void TestNavigation <TParam, TReturn>(SingleResourceNode source, IEdmNavigationProperty navigation, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            QueryNode node;

            if (navigation.Type.IsCollection())
            {
                node = new CollectionNavigationNode(source, navigation, new EdmPathExpression(navigation.Name));
            }
            else
            {
                node = new SingleNavigationNode(source, navigation, new EdmPathExpression(navigation.Name));
            }

            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
Esempio n. 5
0
        private BinaryOperatorNode BuildFilterExpression(SingleResourceNode source, GraphQLFieldSelection selection)
        {
            BinaryOperatorNode compositeNode = null;
            IEdmEntityType     entityType    = source.NavigationSource.EntityType();

            foreach (GraphQLArgument argument in selection.Arguments)
            {
                IEdmProperty edmProperty = FindEdmProperty(entityType, argument.Name.Value);
                var          left        = new SingleValuePropertyAccessNode(source, edmProperty);

                Object value = GetArgumentValue(edmProperty.Type, argument.Value);
                var    right = new ConstantNode(value, ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V4));
                var    node  = new BinaryOperatorNode(BinaryOperatorKind.Equal, left, right);
                compositeNode = ComposeExpression(compositeNode, node);
            }

            return(compositeNode);
        }
Esempio n. 6
0
 public ChangeNavigationPathVisitor(SingleResourceNode parent, IEdmNavigationProperty navigationProperty)
 {
     _singleNavigationNode = new SingleNavigationNode(parent, navigationProperty, null);
 }