Пример #1
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Navigation)
            {
                NavigationPathSegment navigationSegment = (NavigationPathSegment)pathSegment;
                return(navigationSegment.NavigationProperty == NavigationProperty &&
                       navigationSegment.NavigationPropertyName == NavigationPropertyName);
            }

            return(false);
        }
Пример #2
0
        public void Translate_NavigationPropertySegment_To_NavigationPathSegment_Works()
        {
            // Arrange
            IEdmEntitySet             entityset          = _model.FindDeclaredEntitySet("Products");
            IEdmEntityType            entityType         = _model.FindDeclaredType("System.Web.OData.Routing.RoutingCustomer") as IEdmEntityType;
            IEdmNavigationProperty    navigationProperty = entityType.NavigationProperties().First(e => e.Name == "Products");
            NavigationPropertySegment segment            = new NavigationPropertySegment(navigationProperty, entityset);

            // Act
            IEnumerable <ODataPathSegment> segments = _translator.Translate(segment);

            // Assert
            ODataPathSegment      pathSegment           = Assert.Single(segments);
            NavigationPathSegment navigationPathSegment = Assert.IsType <NavigationPathSegment>(pathSegment);

            Assert.Same(navigationProperty, navigationPathSegment.NavigationProperty);
        }
Пример #3
0
        public static IEdmNavigationProperty GetNavigationProperty(this ODataPath path)
        {
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            Contract.Assert(path.Segments != null);
            NavigationPathSegment navigationSegment = (NavigationPathSegment)path.Segments.FirstOrDefault(
                s => s is NavigationPathSegment);

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

            return(navigationSegment.NavigationProperty);
        }
Пример #4
0
        private static void CheckNavigableProperty(ODataPath path, IEdmModel model)
        {
            Contract.Assert(path != null);
            Contract.Assert(model != null);

            foreach (ODataPathSegment segment in path.Segments)
            {
                NavigationPathSegment navigationPathSegment = segment as NavigationPathSegment;

                if (navigationPathSegment != null)
                {
                    if (EdmLibHelpers.IsNotNavigable(navigationPathSegment.NavigationProperty, model))
                    {
                        throw new ODataException(Error.Format(
                                                     SRResources.NotNavigablePropertyUsedInNavigation,
                                                     navigationPathSegment.NavigationProperty.Name));
                    }
                }
            }
        }
 private static HttpStatusCode? GetChangedStatusCodeForNavigationProperty(NavigationPathSegment navigation)
 {
     EdmMultiplicity multiplicity = navigation.NavigationProperty.TargetMultiplicity();
     return multiplicity == EdmMultiplicity.ZeroOrOne || multiplicity == EdmMultiplicity.One ?
         HttpStatusCode.NoContent :
         (HttpStatusCode?)null;
 }