Example #1
0
        public void TypeReferenceComesFromRangeVariable()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.TypeReference.FullName().Should().Be(HardCodedTestModel.GetDogTypeReference().FullName());
        }
Example #2
0
        public void EntitySetComesFromRangeVariable()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Example #3
0
        public void EntityTypeReferenceIsSameAsTypeReference()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.EntityTypeReference.Should().BeSameAs(referenceNode.TypeReference);
        }
Example #4
0
        public void TypeReferenceIsEdmEntityTypeReference()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.TypeReference.Should().BeOfType <EdmEntityTypeReference>();
        }
Example #5
0
        public void CreateParentShouldProduceParentUsingParameters()
        {
            SingleValueNode parent = EndPathBinder.CreateParentFromImplicitRangeVariable(this.bindingState);
            EntityRangeVariableReferenceNode entityRangeVariableReferenceNode = (EntityRangeVariableReferenceNode)parent;

            entityRangeVariableReferenceNode.RangeVariable.Should().BeSameAs(this.bindingState.ImplicitRangeVariable);
        }
Example #6
0
        public void KindIsEntityRangeVariableReferenceNode()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityRangeVariableReference);
        }
Example #7
0
        public void RangeVariableIsSetCorrectly()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.RangeVariable.ShouldBeEntityRangeVariable(HardCodedTestModel.GetDogTypeReference()).And.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Example #8
0
 /// <summary>
 /// Compares entity parameter query nodes query nodes.
 /// </summary>
 /// <param name="left">Left side of comparison</param>
 /// <param name="right">Right side of comparison</param>
 /// <returns>True if equal, otherwise false</returns>
 private bool Compare(EntityRangeVariableReferenceNode left, EntityRangeVariableReferenceNode right)
 {
     if (left.Name != right.Name) return false;
     if (left.TypeReference != right.TypeReference) return false;
     if (left.NavigationSource != right.NavigationSource) return false;
     if (left.EntityTypeReference != right.EntityTypeReference) return false;
     return true;
 }
Example #9
0
        /// <summary>
        /// Visit an EntityRangeVariableReferenceNode
        /// </summary>
        /// <param name="nodeIn">The node to visit</param>
        /// <returns>The translated expression</returns>
        public override Expression Visit(EntityRangeVariableReferenceNode nodeIn)
        {
            this.CheckArgumentNull(nodeIn, "EntityRangeVariableReferenceNode");

            // when this is called for a filter like svc/Customers?$filter=PersonID eq 1, nodeIn.Name has value "$it".
            // when this is called by any/all option, nodeIn.Name is specified by client, it can be any value.
            return(this.ImplicitVariableParameterExpression);
        }
Example #10
0
        private static void BuildFilterWithBinaryOperator()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var firstNameProp = TripPinModel.Person.FindProperty("FirstName");
            var lastNameProp = TripPinModel.Person.FindProperty("LastName");

            var topIt = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);
            var friendsNavNode = new CollectionNavigationNode(friendsProp, topItRef);
            var e0 = new EntityRangeVariable("e0", personTypeRef, friendsNavNode);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);
            var fun1 = new SingleValueFunctionCallNode(
                "startswith",
                new QueryNode[]
                {
                    new SingleValuePropertyAccessNode(e0Ref, firstNameProp),
                    new ConstantNode("var1", "'var1'")
                },
                EdmCoreModel.Instance.GetBoolean(false));

            var friendsNavNode2 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1 = new EntityRangeVariable("e1", personTypeRef, friendsNavNode2);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);
            var fun2 = new SingleValueFunctionCallNode(
                "contains",
                new QueryNode[]
                {
                    new SingleValuePropertyAccessNode(e1Ref, lastNameProp),
                    new ConstantNode("var2", "'var2'")
                },
                EdmCoreModel.Instance.GetBoolean(false));

            // Actually $it also needed, but would not be used in UriBuilder, so omit it here.
            var any2 = new AnyNode(new Collection<RangeVariable> { e1 }, e1)
            {
                Body = fun2,
                Source = friendsNavNode2
            };

            var any1 = new AnyNode(new Collection<RangeVariable> { e0 }, e0)
            {
                Body = new BinaryOperatorNode(BinaryOperatorKind.And, fun1, any2),
                Source = friendsNavNode
            };

            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter = new FilterClause(any1, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());

            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(
            // e0:startswith(e0%2FFirstName%2C'var1') and e0%2FFriends%2Fany(e1:contains(e1%2FLastName%2C'var2')))
        }
 /// <summary>
 /// Writes EntityRangeVariableReferenceNode to string.
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(EntityRangeVariableReferenceNode node)
 {
     return(tabHelper.Prefix + "EntityRangeVariableReferenceNode" +
            tabHelper.Indent(() =>
                             tabHelper.Prefix + "Name = " + node.Name +
                             tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
                             tabHelper.Prefix + "TypeReference = " + node.TypeReference +
                             tabHelper.Prefix + "Range Variable = " + node.RangeVariable
                             ));
 }
 /// <summary>
 /// Translates a <see cref="EntityRangeVariableReferenceNode"/> into a corresponding <see cref="string"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated string.</returns>
 public override string Visit(EntityRangeVariableReferenceNode node)
 {
     if (node.Name == "$it")
     {
         return(string.Empty);
     }
     else
     {
         return(node.Name);
     }
 }
Example #13
0
        public void ShouldThrowNotImplementedIfTypeIsOpen()
        {
            const string         OpenPropertyName     = "Style";
            var                  token                = new EndPathToken(OpenPropertyName, new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetPaintingsSet());
            SingleValueNode      parentNode           = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPaintingTypeReference(), entityCollectionNode));
            var                  propertyNode         = EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode(OpenPropertyName);
        }
Example #14
0
 /// <summary>
 /// Translates a <see cref="EntityRangeVariableReferenceNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(EntityRangeVariableReferenceNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     if (node.Name == "$it")
     {
         return(String.Empty);
     }
     else
     {
         return(node.Name);
     }
 }
Example #15
0
        public void ShouldThrowIfTypeNotOpen()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode      parentNode           = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));
            Action getQueryNode = () => EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            getQueryNode.ShouldThrow <ODataException>().WithMessage(
                Strings.MetadataBinder_PropertyNotDeclared(parentNode.GetEdmTypeReference().FullName(),
                                                           token.Identifier));
        }
Example #16
0
        public void ShouldNotThrowIfTypeNotOpenButAggregateApplied()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode      parentNode           = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));

            var state = new BindingState(this.configuration);

            state.AggregatedPropertyNames = new List <string> {
                "Color"
            };
            var metadataBinder = new MetadataBinder(state);
            var endPathBinder  = new EndPathBinder(metadataBinder.Bind, state);
            var propertyNode   = endPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode("Color");
        }
Example #17
0
 /// <summary>
 /// Compares entity parameter query nodes query nodes.
 /// </summary>
 /// <param name="left">Left side of comparison</param>
 /// <param name="right">Right side of comparison</param>
 /// <returns>True if equal, otherwise false</returns>
 private bool Compare(EntityRangeVariableReferenceNode left, EntityRangeVariableReferenceNode right)
 {
     if (left.Name != right.Name)
     {
         return(false);
     }
     if (left.TypeReference != right.TypeReference)
     {
         return(false);
     }
     if (left.NavigationSource != right.NavigationSource)
     {
         return(false);
     }
     if (left.EntityTypeReference != right.EntityTypeReference)
     {
         return(false);
     }
     return(true);
 }
Example #18
0
        private static void BuildOrderBy()
        {
            var productTypeRef = new EdmEntityTypeReference(V4Model.Product, false);
            var supplierProperty = (IEdmNavigationProperty)V4Model.Product.FindProperty("Supplier");
            var nameProperty = V4Model.Supplier.FindProperty("Name");

            var topIt = new EntityRangeVariable("$it", productTypeRef, V4Model.ProductsSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);
            var supplierNavNode = new SingleNavigationNode(supplierProperty, topItRef);
            var nameNode = new SingleValuePropertyAccessNode(supplierNavNode, nameProperty);

            var orderby = new OrderByClause(null, nameNode, OrderByDirection.Ascending, topIt);
            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(V4Model.ProductsSet)),
                ServiceRoot = V4Root,
                OrderBy = orderby
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/OData/OData.svc/Products?$orderby=Supplier%2FName
        }
Example #19
0
        private static void BuildOrderBy()
        {
            var productTypeRef   = new EdmEntityTypeReference(V4Model.Product, false);
            var supplierProperty = (IEdmNavigationProperty)V4Model.Product.FindProperty("Supplier");
            var nameProperty     = V4Model.Supplier.FindProperty("Name");

            var topIt           = new EntityRangeVariable("$it", productTypeRef, V4Model.ProductsSet);
            var topItRef        = new EntityRangeVariableReferenceNode("$it", topIt);
            var supplierNavNode = new SingleNavigationNode(supplierProperty, topItRef);
            var nameNode        = new SingleValuePropertyAccessNode(supplierNavNode, nameProperty);

            var orderby  = new OrderByClause(null, nameNode, OrderByDirection.Ascending, topIt);
            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(V4Model.ProductsSet)),
                ServiceRoot = V4Root,
                OrderBy     = orderby
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/OData/OData.svc/Products?$orderby=Supplier%2FName
        }
 public void TypeReferenceComesFromRangeVariable()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.TypeReference.FullName().Should().Be(HardCodedTestModel.GetDogTypeReference().FullName());
 }
        public void ShouldThrowNotImplementedIfTypeIsOpen()
        {
            const string OpenPropertyName = "Style";
            var token = new EndPathToken(OpenPropertyName, new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetPaintingsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPaintingTypeReference(), entityCollectionNode));
            var propertyNode = EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode(OpenPropertyName);
        }
        public void ShouldThrowIfTypeNotOpen()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));
            Action getQueryNode = () => EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            getQueryNode.ShouldThrow<ODataException>().WithMessage(
                Strings.MetadataBinder_PropertyNotDeclared(parentNode.GetEdmTypeReference().ODataFullName(),
                                                                                    token.Identifier));

        }
 public void RangeVariableIsSetCorrectly()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.RangeVariable.ShouldBeEntityRangeVariable(HardCodedTestModel.GetDogTypeReference()).And.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
Example #24
0
        public void ShouldNotThrowIfTypeNotOpenButAggregateApplied()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));

            var state = new BindingState(this.configuration);
            state.AggregatedPropertyNames = new List<string> { "Color" };
            var metadataBinder = new MetadataBinder(state);
            var endPathBinder = new EndPathBinder(metadataBinder.Bind, state);
            var propertyNode = endPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode("Color");
        }
Example #25
0
 public override IEnumerable <string> Visit(EntityRangeVariableReferenceNode nodeIn)
 {
     return(_emptyString);
 }
Example #26
0
 private static void VerifyEntityRangeVariableReferenceNodesAreEqual(EntityRangeVariableReferenceNode expected, EntityRangeVariableReferenceNode actual, AssertionHandler assert)
 {
     QueryTestUtils.VerifyTypesAreEqual(expected.TypeReference, actual.TypeReference, assert);
 }
 public void TypeReferenceIsEdmEntityTypeReference()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.TypeReference.Should().BeOfType<EdmEntityTypeReference>();
 }
Example #28
0
        private static void BuildFilterWithNestedAny()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var tripTypeRef   = new EdmEntityTypeReference(TripPinModel.Trip, false);

            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var tripsProp   = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Trips");
            var budgetProp  = TripPinModel.Trip.FindProperty("Budget");

            var topIt    = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);

            var friendsNavNode0 = new CollectionNavigationNode(friendsProp, topItRef);
            var e0    = new EntityRangeVariable("e0", personTypeRef, friendsNavNode0);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);

            var friendsNavNode1 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1    = new EntityRangeVariable("e1", personTypeRef, friendsNavNode1);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);

            var tripNavNode = new CollectionNavigationNode(tripsProp, e1Ref);
            var e2          = new EntityRangeVariable("e2", tripTypeRef, friendsNavNode1);
            var e2Ref       = new EntityRangeVariableReferenceNode("e2", e2);

            var bugetNode = new SingleValuePropertyAccessNode(e2Ref, budgetProp);

            var gt = new BinaryOperatorNode(
                BinaryOperatorKind.GreaterThan,
                bugetNode,
                new ConstantNode(1200, "1200"));

            var any2 = new AnyNode(new Collection <RangeVariable> {
                e2
            }, e2)
            {
                Body = gt, Source = tripNavNode
            };
            var any1 = new AnyNode(new Collection <RangeVariable> {
                e1
            }, e1)
            {
                Body = any2, Source = friendsNavNode1
            };
            var any0 = new AnyNode(new Collection <RangeVariable> {
                e0
            }, e0)
            {
                Body = any1, Source = friendsNavNode0
            };


            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter      = new FilterClause(any0, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(e0:e0%2FFriends%2Fany(e1:e1%2FTrips%2Fany(e2:e2%2FBudget gt 1200)))
        }
 public void EntitySetComesFromRangeVariable()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
 public override string Visit(EntityRangeVariableReferenceNode nodeIn)
 {
     return(WrapWithIdent(string.Format("EntityRangeVariableReferenceNode:[{0}<={1}]", nodeIn.TypeReference, nodeIn.Name)));
 }
 /// <summary>
 /// Translate an EntityRangeVariableReferenceNode.
 /// </summary>
 /// <param name="nodeIn">The node to be translated.</param>
 /// <returns>The original node.</returns>
 public override QueryNode Visit(EntityRangeVariableReferenceNode nodeIn)
 {
     return(nodeIn);
 }
 public override SingleValueNode Visit(EntityRangeVariableReferenceNode nodeIn)
 {
     return(null);
 }
 /// <summary>
 /// Visit an EntityRangeVariableReferenceNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Visit(EntityRangeVariableReferenceNode nodeIn)
 {
     throw new NotImplementedException();
 }
 public void KindIsEntityRangeVariableReferenceNode()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityRangeVariableReference);
 }
 /// <summary>
 /// Writes EntityRangeVariableReferenceNode to string.
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(EntityRangeVariableReferenceNode node)
 {
     return tabHelper.Prefix + "EntityRangeVariableReferenceNode" +
         tabHelper.Indent(() =>
             tabHelper.Prefix + "Name = " + node.Name +
             tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
             tabHelper.Prefix + "TypeReference = " + node.TypeReference +
             tabHelper.Prefix + "Range Variable = " + node.RangeVariable
     );
 }
Example #36
0
        private static void BuildFilterWithNestedAny()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var tripTypeRef = new EdmEntityTypeReference(TripPinModel.Trip, false);

            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var tripsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Trips");
            var budgetProp = TripPinModel.Trip.FindProperty("Budget");

            var topIt = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);

            var friendsNavNode0 = new CollectionNavigationNode(friendsProp, topItRef);
            var e0 = new EntityRangeVariable("e0", personTypeRef, friendsNavNode0);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);

            var friendsNavNode1 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1 = new EntityRangeVariable("e1", personTypeRef, friendsNavNode1);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);

            var tripNavNode = new CollectionNavigationNode(tripsProp, e1Ref);
            var e2 = new EntityRangeVariable("e2", tripTypeRef, friendsNavNode1);
            var e2Ref = new EntityRangeVariableReferenceNode("e2", e2);

            var bugetNode = new SingleValuePropertyAccessNode(e2Ref, budgetProp);

            var gt = new BinaryOperatorNode(
                BinaryOperatorKind.GreaterThan,
                bugetNode,
                new ConstantNode(1200, "1200"));

            var any2 = new AnyNode(new Collection<RangeVariable> { e2 }, e2) { Body = gt, Source = tripNavNode };
            var any1 = new AnyNode(new Collection<RangeVariable> { e1 }, e1) { Body = any2, Source = friendsNavNode1 };
            var any0 = new AnyNode(new Collection<RangeVariable> { e0 }, e0) { Body = any1, Source = friendsNavNode0 };


            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter = new FilterClause(any0, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(e0:e0%2FFriends%2Fany(e1:e1%2FTrips%2Fany(e2:e2%2FBudget gt 1200)))
        }
Example #37
0
        private static void BuildFilterWithBinaryOperator()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var friendsProp   = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var firstNameProp = TripPinModel.Person.FindProperty("FirstName");
            var lastNameProp  = TripPinModel.Person.FindProperty("LastName");

            var topIt          = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef       = new EntityRangeVariableReferenceNode("$it", topIt);
            var friendsNavNode = new CollectionNavigationNode(friendsProp, topItRef);
            var e0             = new EntityRangeVariable("e0", personTypeRef, friendsNavNode);
            var e0Ref          = new EntityRangeVariableReferenceNode("e0", e0);
            var fun1           = new SingleValueFunctionCallNode(
                "startswith",
                new QueryNode[]
            {
                new SingleValuePropertyAccessNode(e0Ref, firstNameProp),
                new ConstantNode("var1", "'var1'")
            },
                EdmCoreModel.Instance.GetBoolean(false));

            var friendsNavNode2 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1    = new EntityRangeVariable("e1", personTypeRef, friendsNavNode2);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);
            var fun2  = new SingleValueFunctionCallNode(
                "contains",
                new QueryNode[]
            {
                new SingleValuePropertyAccessNode(e1Ref, lastNameProp),
                new ConstantNode("var2", "'var2'")
            },
                EdmCoreModel.Instance.GetBoolean(false));

            // Actually $it also needed, but would not be used in UriBuilder, so omit it here.
            var any2 = new AnyNode(new Collection <RangeVariable> {
                e1
            }, e1)
            {
                Body   = fun2,
                Source = friendsNavNode2
            };

            var any1 = new AnyNode(new Collection <RangeVariable> {
                e0
            }, e0)
            {
                Body   = new BinaryOperatorNode(BinaryOperatorKind.And, fun1, any2),
                Source = friendsNavNode
            };

            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter      = new FilterClause(any1, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());

            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(
            // e0:startswith(e0%2FFirstName%2C'var1') and e0%2FFriends%2Fany(e1:contains(e1%2FLastName%2C'var2')))
        }
 public void EntityTypeReferenceIsSameAsTypeReference()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.EntityTypeReference.Should().BeSameAs(referenceNode.TypeReference);
 }
Example #39
0
 private static void VerifyEntityRangeVariableReferenceNodesAreEqual(EntityRangeVariableReferenceNode expected, EntityRangeVariableReferenceNode actual, AssertionHandler assert)
 {
     QueryTestUtils.VerifyTypesAreEqual(expected.TypeReference, actual.TypeReference, assert);
 }