Exemplo n.º 1
0
 /// <summary>
 /// Gets the entity set for this segment.
 /// </summary>
 /// <param name="previousEntitySet">The entity set of the previous path segment.</param>
 /// <returns>
 /// The entity set for this segment.
 /// </returns>
 public override IEdmEntitySet GetEntitySet(IEdmEntitySet previousEntitySet)
 {
     if (NavigationProperty != null && previousEntitySet != null)
     {
         return(previousEntitySet.FindNavigationTarget(NavigationProperty));
     }
     return(null);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the entity set for this segment.
 /// </summary>
 /// <param name="previousEntitySet">The entity set of the previous path segment.</param>
 /// <returns>
 /// The entity set for this segment.
 /// </returns>
 public override IEdmEntitySet GetEntitySet(IEdmEntitySet previousEntitySet)
 {
     if (NavigationProperty != null && previousEntitySet != null)
     {
         // Cast will fail in singleton / containment cases.
         return(previousEntitySet.FindNavigationTarget(NavigationProperty) as IEdmEntitySet);
     }
     return(null);
 }
Exemplo n.º 3
0
        public void GenerateNavigationLink_WorksToGenerateExpectedNavigationLink_ForNonContainedNavigation()
        {
            // Arrange
            IEdmEntityType         myOrder               = (IEdmEntityType)_myOrderModel.FindDeclaredType("NS.MyOrder");
            IEdmEntityType         orderLine             = (IEdmEntityType)_myOrderModel.FindDeclaredType("NS.OrderLine");
            IEdmNavigationProperty nonOrderLinesProperty = myOrder.NavigationProperties().Single(x => x.Name.Equals("NonContainedOrderLines"));

            IEdmEntitySet entitySet = _myOrderModel.FindDeclaredEntitySet("MyOrders");
            IDictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "ID", 42 }
            };

            IDictionary <string, object> parameters2 = new Dictionary <string, object>
            {
                { "ID", 21 }
            };

            IEdmNavigationSource nonContainedOrderLines = entitySet.FindNavigationTarget(nonOrderLinesProperty);
            ODataPath            path = new ODataPath(
                new EntitySetSegment(entitySet),
                new KeySegment(parameters.ToArray(), myOrder, entitySet),
                new NavigationPropertySegment(nonOrderLinesProperty, nonContainedOrderLines),
                new KeySegment(parameters2.ToArray(), orderLine, nonContainedOrderLines));

            IEdmNavigationProperty orderLinesProperty = myOrder.NavigationProperties().Single(x => x.ContainsTarget);
            IEdmContainedEntitySet orderLines         = (IEdmContainedEntitySet)entitySet.FindNavigationTarget(orderLinesProperty);

            var request           = RequestFactory.Create(_myOrderModel);
            var serializerContext = ODataSerializerContextFactory.Create(_myOrderModel, orderLines, path, request);
            var entityContext     = new ResourceContext(serializerContext, orderLine.AsReference(), new { ID = 21 });

            // Act
            Uri uri = entityContext.GenerateSelfLink(false);

            // Assert
            Assert.Equal("http://localhost/OrderLines(21)", uri.AbsoluteUri);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a SingleNavigationNode.
        /// </summary>
        /// <param name="navigationProperty">The navigation property this node represents.</param>
        /// <param name="sourceSet">The entity set that this of the previous segment.</param>
        /// <exception cref="System.ArgumentNullException">Throws if the input navigationProperty or source is null.</exception>
        /// <exception cref="ArgumentException">Throws if the input navigationProperty targets more than one entity.</exception>
        public SingleNavigationNode(IEdmNavigationProperty navigationProperty, IEdmEntitySet sourceSet)
        {
            ExceptionUtils.CheckArgumentNotNull(navigationProperty, "navigationProperty");

            EdmMultiplicity multiplicity = navigationProperty.TargetMultiplicityTemporary();

            if (multiplicity != EdmMultiplicity.One && multiplicity != EdmMultiplicity.ZeroOrOne)
            {
                throw new ArgumentException(ODataErrorStrings.Nodes_CollectionNavigationNode_MustHaveSingleMultiplicity);
            }

            this.navigationProperty  = navigationProperty;
            this.entityTypeReference = (IEdmEntityTypeReference)this.NavigationProperty.Type;
            this.entitySet           = sourceSet != null?sourceSet.FindNavigationTarget(navigationProperty) : null;
        }
        private bool SharesAssociationSet(IEdmEntitySet thisEntitySet, IEdmNavigationProperty thisNavprop, IEdmEntitySet thatEntitySet, IEdmNavigationProperty thatNavprop)
        {
            IEnumerable <IEdmDirectValueAnnotation> enumerable;
            IEnumerable <IEdmDirectValueAnnotation> enumerable2;
            IEnumerable <IEdmDirectValueAnnotation> enumerable3;
            IEnumerable <IEdmDirectValueAnnotation> enumerable4;
            IEnumerable <IEdmDirectValueAnnotation> enumerable5;
            IEnumerable <IEdmDirectValueAnnotation> enumerable6;

            if ((thisEntitySet == thatEntitySet) && (thisNavprop == thatNavprop))
            {
                return(true);
            }
            if ((base.Model.GetAssociationSetName(thisEntitySet, thisNavprop) != base.Model.GetAssociationSetName(thatEntitySet, thatNavprop)) || (base.Model.GetAssociationFullName(thisNavprop) != base.Model.GetAssociationFullName(thatNavprop)))
            {
                return(false);
            }
            if ((base.Model.GetAssociationEndName(thisNavprop) != base.Model.GetAssociationEndName(thatNavprop)) || (thisEntitySet.Name != thatEntitySet.Name))
            {
                return(false);
            }
            IEdmEntitySet set  = thisEntitySet.FindNavigationTarget(thisNavprop);
            IEdmEntitySet set2 = thatEntitySet.FindNavigationTarget(thatNavprop);

            if (set == null)
            {
                if (set2 != null)
                {
                    return(false);
                }
            }
            else
            {
                if (set2 == null)
                {
                    return(false);
                }
                if ((base.Model.GetAssociationEndName(thisNavprop.Partner) != base.Model.GetAssociationEndName(thatNavprop.Partner)) || (set.Name != set2.Name))
                {
                    return(false);
                }
            }
            base.Model.GetAssociationSetAnnotations(thisEntitySet, thisNavprop, out enumerable, out enumerable2, out enumerable3);
            base.Model.GetAssociationSetAnnotations(thatEntitySet, thatNavprop, out enumerable4, out enumerable5, out enumerable6);
            return(((enumerable == enumerable4) && (enumerable2 == enumerable5)) && (enumerable3 == enumerable6));
        }
Exemplo n.º 6
0
        public void GenerateNavigationLink_WorksToGenerateExpectedNavigationLink_ForContainedNavigation(
            bool includeCast,
            string expectedNavigationLink)
        {
            // NOTE: This test is generating a link that does not technically correspond to a valid model (specifically
            //       the extra OrderLines navigation), but it allows us to validate the nested navigation scenario
            //       without twisting the model unnecessarily.

            // Arrange
            IEdmEntityType myOrder   = (IEdmEntityType)_myOrderModel.FindDeclaredType("NS.MyOrder");
            IEdmEntityType orderLine = (IEdmEntityType)_myOrderModel.FindDeclaredType("NS.OrderLine");

            IEdmNavigationProperty orderLinesProperty = myOrder.NavigationProperties().Single(x => x.ContainsTarget);

            IEdmEntitySet entitySet = _myOrderModel.FindDeclaredEntitySet("MyOrders");
            IDictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "ID", 42 }
            };

            IDictionary <string, object> parameters2 = new Dictionary <string, object>
            {
                { "ID", 21 }
            };

            // containment
            IEdmContainedEntitySet orderLines = (IEdmContainedEntitySet)entitySet.FindNavigationTarget(orderLinesProperty);

            ODataPath path = new ODataPath(
                new EntitySetSegment(entitySet),
                new KeySegment(parameters.ToArray(), myOrder, entitySet),
                new NavigationPropertySegment(orderLinesProperty, orderLines),
                new KeySegment(parameters2.ToArray(), orderLine, orderLines));

            var request           = RequestFactory.Create(_myOrderModel);
            var serializerContext = ODataSerializerContextFactory.Create(_myOrderModel, orderLines, path, request);
            var entityContext     = new ResourceContext(serializerContext, orderLine.AsReference(), new { ID = 21 });

            // Act
            Uri uri = entityContext.GenerateNavigationPropertyLink(orderLinesProperty, includeCast);

            // Assert
            Assert.Equal(expectedNavigationLink, uri.AbsoluteUri);
        }
 public ODataUriParserInjectionTests()
 {
     folderType             = oneDriveModel.SchemaElements.OfType <IEdmComplexType>().Single(e => string.Equals(e.Name, "folder"));
     itemType               = oneDriveModel.SchemaElements.OfType <IEdmEntityType>().Single(e => string.Equals(e.Name, "item"));
     specialItemType        = oneDriveModel.SchemaElements.OfType <IEdmEntityType>().Single(e => string.Equals(e.Name, "specialItem"));
     folderProp             = itemType.FindProperty("folder") as IEdmStructuralProperty;
     sizeProp               = itemType.FindProperty("size") as IEdmStructuralProperty;
     driveType              = oneDriveModel.SchemaElements.OfType <IEdmEntityType>().Single(e => string.Equals(e.Name, "drive"));
     itemsNavProp           = driveType.DeclaredNavigationProperties().FirstOrDefault(p => p.Name == "items");
     childrenNavProp        = itemType.DeclaredNavigationProperties().FirstOrDefault(p => p.Name == "children");
     thumbnailsNavProp      = itemType.DeclaredNavigationProperties().FirstOrDefault(p => p.Name == "thumbnails");
     drivesEntitySet        = oneDriveModel.EntityContainer.FindEntitySet("drives");
     driveSingleton         = oneDriveModel.EntityContainer.FindSingleton("drive");
     containedItemsNav      = drivesEntitySet.FindNavigationTarget(itemsNavProp);
     containedthumbnailsNav = containedItemsNav.FindNavigationTarget(thumbnailsNavProp);
     copyOp   = oneDriveModel.SchemaElements.OfType <IEdmOperation>().FirstOrDefault(o => o.Name == "copy");
     searchOp = oneDriveModel.SchemaElements.OfType <IEdmOperation>().FirstOrDefault(o => o.Name == "search");
     shareItemBindCollectionOp = oneDriveModel.SchemaElements.OfType <IEdmOperation>().LastOrDefault(o => o.Name == "sharedWithMe");
 }
        public void TestInitialize()
        {
            this.testModel = Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            this.defaultContainer = this.testModel.EntityContainer;

            this.personSet = this.defaultContainer.FindEntitySet("Persons");
            this.personType = (IEdmEntityType)this.testModel.FindType("TestModel.Person");
            this.employeeType = (IEdmEntityType)this.testModel.FindType("TestModel.Employee");
            this.officeType = (IEdmEntityType)this.testModel.FindType("TestModel.OfficeType");
            this.addressType = (IEdmComplexType)this.testModel.FindType("TestModel.Address");
            this.metropolitanCitySet = this.defaultContainer.FindEntitySet("MetropolitanCities");
            this.metropolitanCityType = (IEdmEntityType)this.testModel.FindType("TestModel.MetropolitanCityType");
            this.boss = this.defaultContainer.FindSingleton("Boss");
            this.containedOfficeNavigationProperty = (IEdmNavigationProperty)this.metropolitanCityType.FindProperty("ContainedOffice");
            this.containedOfficeSet = (IEdmContainedEntitySet)metropolitanCitySet.FindNavigationTarget(this.containedOfficeNavigationProperty);
            this.containedMetropolitanCityNavigationProperty = (IEdmNavigationProperty)this.officeType.FindProperty("ContainedCity");
            this.containedMetropolitanCitySet = (IEdmContainedEntitySet)containedOfficeSet.FindNavigationTarget(this.containedMetropolitanCityNavigationProperty);
        }
        private void ProcessAssociationSet(IEdmEntitySet entitySet, IEdmNavigationProperty property)
        {
            IEnumerable <IEdmDirectValueAnnotation> enumerable;
            IEnumerable <IEdmDirectValueAnnotation> enumerable2;
            IEnumerable <IEdmDirectValueAnnotation> enumerable3;

            base.Model.GetAssociationSetAnnotations(entitySet, property, out enumerable, out enumerable2, out enumerable3);
            this.schemaWriter.WriteAssociationSetElementHeader(entitySet, property);
            this.ProcessAnnotations(enumerable);
            this.ProcessAssociationSetEnd(entitySet, property, enumerable2);
            IEdmEntitySet set = entitySet.FindNavigationTarget(property);

            if (set != null)
            {
                this.ProcessAssociationSetEnd(set, property.Partner, enumerable3);
            }
            this.VisitPrimitiveElementAnnotations(enumerable);
            this.schemaWriter.WriteEndElement();
        }
        public void TestInitialize()
        {
            this.testModel = Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            this.defaultContainer = this.testModel.EntityContainer;

            this.personSet            = this.defaultContainer.FindEntitySet("Persons");
            this.personType           = (IEdmEntityType)this.testModel.FindType("TestModel.Person");
            this.employeeType         = (IEdmEntityType)this.testModel.FindType("TestModel.Employee");
            this.officeType           = (IEdmEntityType)this.testModel.FindType("TestModel.OfficeType");
            this.addressType          = (IEdmComplexType)this.testModel.FindType("TestModel.Address");
            this.metropolitanCitySet  = this.defaultContainer.FindEntitySet("MetropolitanCities");
            this.metropolitanCityType = (IEdmEntityType)this.testModel.FindType("TestModel.MetropolitanCityType");
            this.boss = this.defaultContainer.FindSingleton("Boss");
            this.containedOfficeNavigationProperty = (IEdmNavigationProperty)this.metropolitanCityType.FindProperty("ContainedOffice");
            this.containedOfficeSet = (IEdmContainedEntitySet)metropolitanCitySet.FindNavigationTarget(this.containedOfficeNavigationProperty);
            this.containedMetropolitanCityNavigationProperty = (IEdmNavigationProperty)this.officeType.FindProperty("ContainedCity");
            this.containedMetropolitanCitySet = (IEdmContainedEntitySet)containedOfficeSet.FindNavigationTarget(this.containedMetropolitanCityNavigationProperty);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Finds the navigation target of this navigation property given a server entity set.
        /// </summary>
        /// <param name="sourceServerEntitySet">The source server entity set.</param>
        /// <returns>The navigation target or null if one couldn't be found.</returns>
        internal EdmEntitySetFacade FindNavigationTarget(IEdmEntitySet sourceServerEntitySet)
        {
            Debug.Assert(sourceServerEntitySet != null, "sourceServerEntitySet != null");

            // if no property could be found, then there is no way to get the target.
            if (this.serverProperty == null)
            {
                return(null);
            }

            // find the target using the server property.
            IEdmEntitySet serverTarget = sourceServerEntitySet.FindNavigationTarget(this.serverProperty);

            if (serverTarget == null)
            {
                return(null);
            }

            // if a target was found, wrap it in a new facade and return it.
            return(this.modelFacade.GetOrCreateEntityContainerFacade(serverTarget.Container).GetOrCreateEntitySetFacade(serverTarget));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the target entity set for the given function import.
        /// </summary>
        /// <param name="functionImport">The function import.</param>
        /// <param name="sourceEntitySet">The source entity set.</param>
        /// <param name="model">The model.</param>
        /// <returns>The target entity set of the function import or null if it could not be determined.</returns>
        internal static IEdmEntitySet GetTargetEntitySet(this IEdmFunctionImport functionImport, IEdmEntitySet sourceEntitySet, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            IEdmEntitySet targetEntitySet;

            if (functionImport.TryGetStaticEntitySet(out targetEntitySet))
            {
                return(targetEntitySet);
            }

            if (sourceEntitySet == null)
            {
                return(null);
            }

            if (functionImport.IsBindable && functionImport.Parameters.Any())
            {
                IEdmFunctionParameter parameter;
                IEnumerable <IEdmNavigationProperty> path;
                if (functionImport.TryGetRelativeEntitySetPath(model, out parameter, out path))
                {
                    // TODO: throw better exception
                    ExceptionUtil.ThrowSyntaxErrorIfNotValid(parameter == functionImport.Parameters.First());
                    targetEntitySet = sourceEntitySet;
                    foreach (var navigation in path)
                    {
                        targetEntitySet = targetEntitySet.FindNavigationTarget(navigation);
                        if (targetEntitySet == null)
                        {
                            return(null);
                        }
                    }

                    return(targetEntitySet);
                }
            }

            return(null);
        }
Exemplo n.º 13
0
        private void ProcessAssociationSet(IEdmEntitySet entitySet, IEdmNavigationProperty property)
        {
            IEnumerable <IEdmDirectValueAnnotation> associationSetAnnotations;
            IEnumerable <IEdmDirectValueAnnotation> end1Annotations;
            IEnumerable <IEdmDirectValueAnnotation> end2Annotations;

            this.Model.GetAssociationSetAnnotations(entitySet, property, out associationSetAnnotations, out end1Annotations, out end2Annotations);

            this.schemaWriter.WriteAssociationSetElementHeader(entitySet, property);
            this.ProcessAnnotations(associationSetAnnotations);

            this.ProcessAssociationSetEnd(entitySet, property, end1Annotations);

            IEdmEntitySet otherEntitySet = entitySet.FindNavigationTarget(property);

            if (otherEntitySet != null)
            {
                this.ProcessAssociationSetEnd(otherEntitySet, property.Partner, end2Annotations);
            }

            this.VisitPrimitiveElementAnnotations(associationSetAnnotations);
            this.schemaWriter.WriteEndElement();
        }
Exemplo n.º 14
0
        public void CanAddBinding_For_DerivedNavigationProperty()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle)).DerivesFrom(vehicle);
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);
            var navProperty   = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            vehicles.AddBinding(navProperty, manufacturers);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            var motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));
            var edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer",
                                                                                  typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);

            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("vehicles");

            Assert.NotNull(entitySet);

            var target = entitySet.FindNavigationTarget(edmNavProperty);

            Assert.NotNull(target);
            Assert.Equal("manufacturers", target.Name);

            var binding = Assert.Single(entitySet.FindNavigationPropertyBindings(edmNavProperty));

            Assert.Same(target, binding.Target);
            Assert.Equal("Microsoft.AspNet.OData.Test.Builder.TestModels.Motorcycle/Manufacturer", binding.Path.Path);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Tries to get entity set.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="model">The model.</param>
        /// <param name="entitySet">The entity set.</param>
        /// <returns>
        /// True  if it gets and entitySet or false if it can't
        /// </returns>
        public static bool TryGetEntitySetAndEntityType(Uri uri, IEdmModel model, out IEdmEntitySet entitySet)
        {
            IEdmEntitySet currentEntitySet = null;

            entitySet = null;
            foreach (string segment in uri.Segments)
            {
                string segmentValue = segment.Replace("/", String.Empty);

                if (segmentValue.Length == 0)
                {
                    continue;
                }

                // lopping off key pieces as we don't care
                int i = segment.IndexOf('(');
                if (i > -1)
                {
                    segmentValue = segment.Remove(i);
                }

                IEdmEntityContainer container = model.EntityContainers().First();
                // If there is no entitySet we need to find out which one it is
                if (currentEntitySet == null)
                {
                    IEdmEntitySet foundEntitySet = container.FindEntitySet(segmentValue);
                    if (foundEntitySet != null)
                    {
                        currentEntitySet = foundEntitySet;
                    }
                    else
                    {
                        // check to see if there the current segment is a service operation
                        IEdmFunctionImport functionImport = container.FunctionImports().SingleOrDefault(fi => fi.Name == segmentValue);
                        if (functionImport != null)
                        {
                            IEdmEntitySet functionEntitySet = null;
                            if (functionImport.TryGetStaticEntitySet(out functionEntitySet))
                            {
                                currentEntitySet = functionEntitySet;
                            }
                        }
                    }
                }
                else
                {
                    IEdmNavigationProperty navigationProperty = currentEntitySet.ElementType.NavigationProperties().SingleOrDefault(np => np.Name == segmentValue);
                    if (navigationProperty != null)
                    {
                        currentEntitySet = currentEntitySet.FindNavigationTarget(navigationProperty);
                    }
                    else
                    {
                        // Need to update this a little so it works for Actions/Functions
                        IEdmFunctionImport functionImport = container.FunctionImports().SingleOrDefault(fi => fi.IsBindable == true && fi.Name == segmentValue);
                        if (functionImport != null)
                        {
                            IEdmEntitySet functionEntitySet = null;
                            if (functionImport.TryGetStaticEntitySet(out functionEntitySet))
                            {
                                currentEntitySet = functionEntitySet;
                            }
                        }
                    }
                }
            }

            if (currentEntitySet != null)
            {
                entitySet = currentEntitySet;
                return(true);
            }

            entitySet = null;

            return(false);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Gets the entity set for this segment.
 /// </summary>
 /// <param name="previousEntitySet">The entity set of the previous path segment.</param>
 /// <returns>
 /// The entity set for this segment.
 /// </returns>
 public override IEdmEntitySet GetEntitySet(IEdmEntitySet previousEntitySet)
 {
     if (NavigationProperty != null && previousEntitySet != null)
     {
         // Cast will fail in singleton / containment cases.
         return previousEntitySet.FindNavigationTarget(NavigationProperty) as IEdmEntitySet;
     }
     return null;
 }
Exemplo n.º 17
0
        private bool SharesAssociationSet(IEdmEntitySet thisEntitySet, IEdmNavigationProperty thisNavprop, IEdmEntitySet thatEntitySet, IEdmNavigationProperty thatNavprop)
        {
            if (thisEntitySet == thatEntitySet && thisNavprop == thatNavprop)
            {
                return(true);
            }

            // Association Set
            if (!(this.Model.GetAssociationSetName(thisEntitySet, thisNavprop) == this.Model.GetAssociationSetName(thatEntitySet, thatNavprop) &&
                  this.Model.GetAssociationFullName(thisNavprop) == this.Model.GetAssociationFullName(thatNavprop)))
            {
                return(false);
            }

            // End 1
            if (!(this.Model.GetAssociationEndName(thisNavprop) == this.Model.GetAssociationEndName(thatNavprop) &&
                  thisEntitySet.Name == thatEntitySet.Name))
            {
                return(false);
            }

            // End 2
            IEdmEntitySet thisOtherEntitySet = thisEntitySet.FindNavigationTarget(thisNavprop);
            IEdmEntitySet thatOtherEntitySet = thatEntitySet.FindNavigationTarget(thatNavprop);

            if (thisOtherEntitySet == null)
            {
                if (thatOtherEntitySet != null)
                {
                    return(false);
                }
            }
            else
            {
                if (thatOtherEntitySet == null)
                {
                    return(false);
                }

                if (!(this.Model.GetAssociationEndName(thisNavprop.Partner) == this.Model.GetAssociationEndName(thatNavprop.Partner) &&
                      thisOtherEntitySet.Name == thatOtherEntitySet.Name))
                {
                    return(false);
                }
            }

            // Annotations
            IEnumerable <IEdmDirectValueAnnotation> thisAssociationSetAnnotations;
            IEnumerable <IEdmDirectValueAnnotation> thisEnd1Annotations;
            IEnumerable <IEdmDirectValueAnnotation> thisEnd2Annotations;

            this.Model.GetAssociationSetAnnotations(thisEntitySet, thisNavprop, out thisAssociationSetAnnotations, out thisEnd1Annotations, out thisEnd2Annotations);

            IEnumerable <IEdmDirectValueAnnotation> thatAssociationSetAnnotations;
            IEnumerable <IEdmDirectValueAnnotation> thatEnd1Annotations;
            IEnumerable <IEdmDirectValueAnnotation> thatEnd2Annotations;

            this.Model.GetAssociationSetAnnotations(thatEntitySet, thatNavprop, out thatAssociationSetAnnotations, out thatEnd1Annotations, out thatEnd2Annotations);

            if (!(thisAssociationSetAnnotations == thatAssociationSetAnnotations &&
                  thisEnd1Annotations == thatEnd1Annotations &&
                  thisEnd2Annotations == thatEnd2Annotations))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets the target entity set for the given function import.
        /// </summary>
        /// <param name="functionImport">The function import.</param>
        /// <param name="sourceEntitySet">The source entity set.</param>
        /// <param name="model">The model.</param>
        /// <returns>The target entity set of the function import or null if it could not be determined.</returns>
        internal static IEdmEntitySet GetTargetEntitySet(this IEdmFunctionImport functionImport, IEdmEntitySet sourceEntitySet, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            IEdmEntitySet targetEntitySet;
            if (functionImport.TryGetStaticEntitySet(out targetEntitySet))
            {
                return targetEntitySet;
            }

            if (sourceEntitySet == null)
            {
                return null;
            }

            if (functionImport.IsBindable && functionImport.Parameters.Any())
            {
                IEdmFunctionParameter parameter;
                IEnumerable<IEdmNavigationProperty> path;
                if (functionImport.TryGetRelativeEntitySetPath(model, out parameter, out path))
                {
                    // TODO: throw better exception
                    WebUtil.CheckSyntaxValid(parameter == functionImport.Parameters.First());
                    targetEntitySet = sourceEntitySet;
                    foreach (var navigation in path)
                    {
                        targetEntitySet = targetEntitySet.FindNavigationTarget(navigation);
                        if (targetEntitySet == null)
                        {
                            return null;
                        }
                    }

                    return targetEntitySet;
                }
            }

            return null;
        }
 /// <summary>
 /// Gets the entity set for this segment.
 /// </summary>
 /// <param name="previousEntitySet">The entity set of the previous path segment.</param>
 /// <returns>
 /// The entity set for this segment.
 /// </returns>
 public override IEdmEntitySet GetEntitySet(IEdmEntitySet previousEntitySet)
 {
     if (NavigationProperty != null && previousEntitySet != null)
     {
         return previousEntitySet.FindNavigationTarget(NavigationProperty);
     }
     return null;
 }
Exemplo n.º 20
0
 public bool IsAssociationSetRegistered(IEdmEntitySet entitySet, IEdmNavigationProperty navigation)
 {
     return this.registeredAssociationSets.Any(s => s.Key == entitySet && s.Value == navigation) ||
            this.registeredAssociationSets.Any(s => s.Key == entitySet.FindNavigationTarget(navigation) && s.Value == navigation.Partner);
 }
Exemplo n.º 21
0
 public bool IsAssociationSetRegistered(IEdmEntitySet entitySet, IEdmNavigationProperty navigation)
 {
     return(this.registeredAssociationSets.Any(s => s.Key == entitySet && s.Value == navigation) ||
            this.registeredAssociationSets.Any(s => s.Key == entitySet.FindNavigationTarget(navigation) && s.Value == navigation.Partner));
 }
        public void ConvertEntityContainer()
        {
            var taupoModel = new EntityModelSchema()
            {
                new EntityContainer("MyContainer")
                {
                    new EntitySet("Customers", "Customer"),
                    new EntitySet("Orders", "Order")
                    {
                        new AttributeAnnotation()
                        {
                            Content = new XAttribute(this.annotationNamespace + "foo1", "bar1")
                        },
                    },
                    new AssociationSet("CustomerOrders", "CustomerOrder")
                    {
                        new AssociationSetEnd("Order", "Orders"),
                        new AssociationSetEnd("Customer", "Customers")
                    },
                    new FunctionImport("FunctionImport1")
                    {
                        ReturnTypes = { new FunctionImportReturnType(DataTypes.CollectionOfEntities("Customer"), "Customers") },
                        Parameters  = { new FunctionParameter("ExcludingId", EdmDataTypes.Int32) },
                        Annotations = { new AttributeAnnotation()
                                        {
                                            Content = new XAttribute(this.annotationNamespace + "foo5", "bar5")
                                        } },
                    },
                    new AttributeAnnotation()
                    {
                        Content = new XAttribute(this.annotationNamespace + "foo4", "bar4")
                    },
                },
                new EntityType("Customer")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                },
                new EntityType("Order")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                },
                new AssociationType("CustomerOrder")
                {
                    new AssociationEnd("Customer", "Customer", EndMultiplicity.One, OperationAction.Cascade),
                    new AssociationEnd("Order", "Order", EndMultiplicity.Many),
                },
            }
            .ApplyDefaultNamespace("NS1")
            .Resolve();

            IEdmModel result = this.converter.ConvertToEdmModel(taupoModel);

            IEdmEntityType customer = (IEdmEntityType)result.FindType("NS1.Customer");
            IEdmEntityType order    = (IEdmEntityType)result.FindType("NS1.Order");

            IEdmEntityContainer convertedContainer = result.EntityContainer;

            Assert.AreEqual("MyContainer", convertedContainer.Name);
            Assert.AreEqual(3, convertedContainer.Elements.Count());
            Assert.AreEqual(2, convertedContainer.Elements.OfType <IEdmEntitySet>().Count());
            Assert.AreEqual(1, convertedContainer.Elements.OfType <IEdmOperationImport>().Count());

            Assert.AreEqual(1, result.DirectValueAnnotations(convertedContainer).Count());
            Assert.AreEqual("bogus", result.DirectValueAnnotations(convertedContainer).First().NamespaceUri);
            Assert.AreEqual("foo4", result.DirectValueAnnotations(convertedContainer).First().Name);
            Assert.AreEqual("bar4", (((IEdmDirectValueAnnotation)result.DirectValueAnnotations(convertedContainer).First()).Value as IEdmStringValue).Value);

            IEdmEntitySet convertedCustomerSet = convertedContainer.Elements.OfType <IEdmEntitySet>().ElementAt(0);

            Assert.AreEqual("Customers", convertedCustomerSet.Name);
            Assert.AreEqual(result.FindType("NS1.Customer"), convertedCustomerSet.ElementType);

            Assert.AreEqual(0, result.DirectValueAnnotations(convertedCustomerSet).Count(a => a.NamespaceUri == "bogus"));

            IEdmEntitySet convertedOrderSet = convertedContainer.Elements.OfType <IEdmEntitySet>().ElementAt(1);

            Assert.AreEqual("Orders", convertedOrderSet.Name);
            Assert.AreEqual(result.FindType("NS1.Order"), convertedOrderSet.ElementType);

            var annotations = result.DirectValueAnnotations(convertedOrderSet).Where(a => a.NamespaceUri == "bogus");

            Assert.AreEqual(1, annotations.Count());
            Assert.AreEqual("foo1", annotations.First().Name);
            Assert.AreEqual("bar1", (((IEdmDirectValueAnnotation)annotations.First()).Value as IEdmStringValue).Value);

            var toOrder = customer.NavigationProperties().First();

            Assert.AreSame(convertedOrderSet, convertedCustomerSet.FindNavigationTarget(toOrder));
            Assert.AreEqual("CustomerOrders", result.GetAssociationSetName(convertedCustomerSet, toOrder));

            var toCustomer = order.NavigationProperties().First();

            Assert.AreSame(convertedCustomerSet, convertedOrderSet.FindNavigationTarget(toCustomer));
            Assert.AreEqual("CustomerOrders", result.GetAssociationSetName(convertedOrderSet, toCustomer));

            IEdmOperationImport convertedFunctionImport = convertedContainer.Elements.OfType <IEdmOperationImport>().First();

            Assert.AreEqual("FunctionImport1", convertedFunctionImport.Name);
            IEdmEntitySet eset;

            Assert.IsTrue(convertedFunctionImport.TryGetStaticEntitySet(out eset));
            Assert.AreEqual(convertedCustomerSet, eset);

            Assert.AreEqual(EdmTypeKind.Collection, convertedFunctionImport.ReturnType.TypeKind());
            Assert.AreEqual(null, convertedFunctionImport.ReturnType.FullName());

            Assert.AreEqual(1, convertedFunctionImport.Parameters.Count());
            Assert.AreEqual("ExcludingId", convertedFunctionImport.Parameters.First().Name);
            Assert.AreEqual(EdmTypeKind.Primitive, convertedFunctionImport.Parameters.First().Type.TypeKind());

            Assert.AreEqual(1, result.DirectValueAnnotations(convertedFunctionImport).Count());
            Assert.AreEqual("bogus", result.DirectValueAnnotations(convertedFunctionImport).First().NamespaceUri);
            Assert.AreEqual("foo5", result.DirectValueAnnotations(convertedFunctionImport).First().Name);
            Assert.AreEqual("bar5", (((IEdmDirectValueAnnotation)result.DirectValueAnnotations(convertedFunctionImport).First()).Value as IEdmStringValue).Value);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Creates a CollectionNavigationNode.
 /// </summary>
 /// <param name="navigationProperty">The navigation property that defines the collection node.</param>
 /// <param name="sourceSet">The source entity set.</param>
 /// <returns>The collection node.</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input navigation property is null.</exception>
 /// <exception cref="ArgumentException">Throws if the input navigation doesn't target a collection.</exception>
 public CollectionNavigationNode(IEdmNavigationProperty navigationProperty, IEdmEntitySet sourceSet)
     : this(navigationProperty)
 {
     this.entitySet = sourceSet != null?sourceSet.FindNavigationTarget(navigationProperty) : null;
 }
        /// <summary>
        /// Finds the navigation target of this navigation property given a server entity set.
        /// </summary>
        /// <param name="sourceServerEntitySet">The source server entity set.</param>
        /// <returns>The navigation target or null if one couldn't be found.</returns>
        internal EdmEntitySetFacade FindNavigationTarget(IEdmEntitySet sourceServerEntitySet)
        {
            Debug.Assert(sourceServerEntitySet != null, "sourceServerEntitySet != null");

            // if no property could be found, then there is no way to get the target.
            if (this.serverProperty == null)
            {
                return null;
            }

            // find the target using the server property.
            IEdmEntitySet serverTarget = sourceServerEntitySet.FindNavigationTarget(this.serverProperty);
            if (serverTarget == null)
            {
                return null;
            }

            // if a target was found, wrap it in a new facade and return it.
            return this.modelFacade.GetOrCreateEntityContainerFacade(serverTarget.Container).GetOrCreateEntitySetFacade(serverTarget);
        }