예제 #1
0
        /// <summary>
        /// Try to bind the idenfier as property segment,
        /// Append it into path.
        /// </summary>
        private static bool TryBindPropertySegment(string identifier, string parenthesisExpressions, IEdmModel model,
                                                   IList <PathSegment> path,
                                                   PathParserSettings settings)
        {
            PathSegment preSegment = path.LastOrDefault();

            if (preSegment == null || !preSegment.IsSingle)
            {
                return(false);
            }

            IEdmStructuredType structuredType = preSegment.EdmType as IEdmStructuredType;

            if (structuredType == null)
            {
                return(false);
            }

            IEdmProperty property = structuredType.ResolveProperty(identifier, settings.EnableCaseInsensitive);

            if (property == null)
            {
                return(false);
            }

            PathSegment segment;

            if (property.PropertyKind == EdmPropertyKind.Navigation)
            {
                var navigationProperty = (IEdmNavigationProperty)property;

                IEdmNavigationSource navigationSource = null;
                if (preSegment.NavigationSource != null)
                {
                    IEdmPathExpression bindingPath;
                    navigationSource = preSegment.NavigationSource.FindNavigationTarget(navigationProperty, path, out bindingPath);
                }

                // Relationship between TargetMultiplicity and navigation property:
                //  1) EdmMultiplicity.Many <=> collection navigation property
                //  2) EdmMultiplicity.ZeroOrOne <=> nullable singleton navigation property
                //  3) EdmMultiplicity.One <=> non-nullable singleton navigation property
                segment = new NavigationSegment(navigationProperty, navigationSource, identifier);
            }
            else
            {
                segment = new PropertySegment((IEdmStructuralProperty)property, preSegment.NavigationSource, identifier);
            }

            path.Add(segment);

            if (parenthesisExpressions != null && !property.Type.IsCollection() && !property.Type.AsCollection().ElementType().IsEntity())
            {
                throw new Exception($"Invalid '{parenthesisExpressions}' after property '{identifier}'.");
            }

            TryBindKeySegment(parenthesisExpressions, path);
            return(true);
        }
예제 #2
0
        /// <inheritdoc/>
        public override bool Match(PathSegment other)
        {
            NavigationSegment otherNavigationSegment = other as NavigationSegment;

            if (otherNavigationSegment == null)
            {
                return(false);
            }

            return(ReferenceEquals(NavigationProperty, otherNavigationSegment.NavigationProperty));
        }