private static void AddLinkInfoToRouteData(HttpControllerContext controllerContext, ODataPath odataPath) { KeySegment keyValueSegment = odataPath.Segments.OfType <KeySegment>().First(); controllerContext.AddKeyValueToRouteData(keyValueSegment); KeySegment relatedKeySegment = odataPath.Segments.Last() as KeySegment; if (relatedKeySegment != null) { controllerContext.AddKeyValueToRouteData(relatedKeySegment, ODataRouteConstants.RelatedKey); } }
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw new ArgumentNullException("odataPath"); } if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } if (actionMap == null) { throw new ArgumentNullException("actionMap"); } HttpMethod requestMethod = controllerContext.Request.Method; if (odataPath.PathTemplate == "~/entityset/key/navigation/$ref" && requestMethod == HttpMethod.Get) { KeySegment keyValueSegment = odataPath.Segments[1] as KeySegment; controllerContext.AddKeyValueToRouteData(keyValueSegment); NavigationPropertyLinkSegment navigationLinkSegment = odataPath.Segments[2] as NavigationPropertyLinkSegment; IEdmNavigationProperty navigationProperty = navigationLinkSegment.NavigationProperty; IEdmEntityType declaredType = navigationProperty.DeclaringType as IEdmEntityType; string action = requestMethod + "LinksFor" + navigationProperty.Name + "From" + declaredType.Name; return(actionMap.Contains(action) ? action : requestMethod + "LinksFor" + navigationProperty.Name); } return(base.SelectAction(odataPath, controllerContext, actionMap)); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } string prefix; ComplexCastPathSegment cast; IEdmProperty property = GetProperty(odataPath, controllerContext.Request.Method, out prefix, out cast); IEdmEntityType declaringType = property == null ? null : property.DeclaringType as IEdmEntityType; if (declaringType != null) { string actionName; if (cast == null) { actionName = actionMap.FindMatchingAction( prefix + property.Name + "From" + declaringType.Name, prefix + property.Name); } else { // for example: GetCityOfSubAddressFromVipCustomer or GetCityOfSubAddress actionName = actionMap.FindMatchingAction( prefix + property.Name + "Of" + cast.CastType.Name + "From" + declaringType.Name, prefix + property.Name + "Of" + cast.CastType.Name); } if (actionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } return(actionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } if (controllerContext.Request.Method == HttpMethod.Get) { string actionName = null; switch (odataPath.PathTemplate) { case "~/entityset/key/cast/function": case "~/entityset/key/function": actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: false); if (actionName != null) { controllerContext.AddKeyValueToRouteData(odataPath); } break; case "~/entityset/cast/function": case "~/entityset/function": actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: true); break; case "~/singleton/function": case "~/singleton/cast/function": actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: false); break; } if (actionName != null) { controllerContext.AddFunctionParameterToRouteData(odataPath.Segments.Last() as BoundFunctionPathSegment); return(actionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } if (controllerContext.Request.Method == HttpMethod.Post) { switch (odataPath.PathTemplate) { case "~/entityset/key/cast/action": case "~/entityset/key/action": string actionName = GetAction(odataPath).SelectAction(actionMap, isCollection: false); if (actionName != null) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } return(actionName); case "~/entityset/cast/action": case "~/entityset/action": return(GetAction(odataPath).SelectAction(actionMap, isCollection: true)); case "~/singleton/action": case "~/singleton/cast/action": return(GetAction(odataPath).SelectAction(actionMap, isCollection: false)); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } if (controllerContext.Request.Method == HttpMethod.Post) { switch (odataPath.PathTemplate) { case "~/entityset/key/cast/action": case "~/entityset/key/action": string actionName = GetAction(odataPath).SelectAction(actionMap, isCollection: false); if (actionName != null) { controllerContext.AddKeyValueToRouteData(odataPath); } return(actionName); case "~/entityset/cast/action": case "~/entityset/action": return(GetAction(odataPath).SelectAction(actionMap, isCollection: true)); case "~/singleton/action": case "~/singleton/cast/action": return(GetAction(odataPath).SelectAction(actionMap, isCollection: false)); } } return(null); }
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if ((odataPath.PathTemplate == "~/entityset/key/navigation") || (odataPath.PathTemplate == "~/entityset/key/cast/navigation")) { NavigationPropertySegment segment = odataPath.Segments.Last <ODataPathSegment>() as NavigationPropertySegment; IEdmNavigationProperty navigationProperty = segment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringType as IEdmEntityType; if (declaringType != null) { string prefix = ODataHelper.GetHttpPrefix(controllerContext.Request.Method.ToString()); if (string.IsNullOrEmpty(prefix)) { return(null); } KeySegment segment2 = odataPath.Segments[1] as KeySegment; controllerContext.AddKeyValueToRouteData(segment2); string key = prefix + navigationProperty.Name + "On" + declaringType.Name; return(actionMap.Contains(key) ? key : (prefix + navigationProperty.Name)); } } return(null); }
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath.PathTemplate == "~/entityset/key/property" || odataPath.PathTemplate == "~/entityset/key/cast/property") { var segment = odataPath.Segments.Last() as PropertySegment; var property = segment.Property; var declareType = property.DeclaringType as IEdmEntityType; if (declareType != null) { var key = odataPath.Segments[1] as KeySegment; controllerContext.AddKeyValueToRouteData(key); string prefix = ODataHelper.GetHttpPrefix(controllerContext.Request.Method.ToString()); if (string.IsNullOrEmpty(prefix)) { return(null); } string action = prefix + property.Name + "From" + declareType.Name; return(actionMap.Contains(action) ? action : prefix + property.Name); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } if (odataPath.PathTemplate == "~/entityset/key" || odataPath.PathTemplate == "~/entityset/key/cast") { HttpMethod httpMethod = controllerContext.Request.Method; string httpMethodName; switch (httpMethod.ToString().ToUpperInvariant()) { case "GET": httpMethodName = "Get"; break; case "PUT": httpMethodName = "Put"; break; case "PATCH": case "MERGE": httpMethodName = "Patch"; break; case "DELETE": httpMethodName = "Delete"; break; default: return(null); } Contract.Assert(httpMethodName != null); IEdmEntityType entityType = (IEdmEntityType)odataPath.EdmType; // e.g. Try GetCustomer first, then fallback on Get action name string actionName = actionMap.FindMatchingAction( httpMethodName + entityType.Name, httpMethodName); if (actionName != null) { KeySegment keySegment = (KeySegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keySegment); return(actionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } HttpMethod method = controllerContext.Request.Method; string actionNamePrefix = GetActionMethodPrefix(method); if (actionNamePrefix == null) { return(null); } if (odataPath.PathTemplate == "~/entityset/key/navigation" || odataPath.PathTemplate == "~/entityset/key/navigation/$count" || odataPath.PathTemplate == "~/entityset/key/cast/navigation" || odataPath.PathTemplate == "~/entityset/key/cast/navigation/$count" || odataPath.PathTemplate == "~/singleton/navigation" || odataPath.PathTemplate == "~/singleton/navigation/$count" || odataPath.PathTemplate == "~/singleton/cast/navigation" || odataPath.PathTemplate == "~/singleton/cast/navigation/$count") { NavigationPropertySegment navigationSegment = (odataPath.Segments.Last() as NavigationPropertySegment) ?? odataPath.Segments[odataPath.Segments.Count - 2] as NavigationPropertySegment; IEdmNavigationProperty navigationProperty = navigationSegment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringType as IEdmEntityType; // It is not valid to *Post* to any non-collection valued navigation property. if (navigationProperty.TargetMultiplicity() != EdmMultiplicity.Many && method == HttpMethod.Post) { return(null); } // It is not valid to *Put/Patch" to any collection-valued navigation property. if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many && (method == HttpMethod.Put || "PATCH" == method.Method.ToUpperInvariant())) { return(null); } // *Get* is the only supported method for $count request. if (odataPath.Segments.Last() is CountSegment && method != HttpMethod.Get) { return(null); } if (declaringType != null) { // e.g. Try GetNavigationPropertyFromDeclaringType first, then fallback on GetNavigationProperty action name string actionName = actionMap.FindMatchingAction( actionNamePrefix + navigationProperty.Name + "From" + declaringType.Name, actionNamePrefix + navigationProperty.Name); if (actionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { KeySegment keyValueSegment = (KeySegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment); } return(actionName); } } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } string actionName = null; DynamicPathSegment dynamicPropertSegment = null; switch (odataPath.PathTemplate) { case "~/entityset/key/dynamicproperty": case "~/entityset/key/cast/dynamicproperty": case "~/singleton/dynamicproperty": case "~/singleton/cast/dynamicproperty": dynamicPropertSegment = odataPath.Segments.Last() as DynamicPathSegment; if (dynamicPropertSegment == null) { return(null); } if (controllerContext.Request.Method == HttpMethod.Get) { string actionNamePrefix = String.Format(CultureInfo.InvariantCulture, "Get{0}", _actionName); actionName = actionMap.FindMatchingAction(actionNamePrefix); } break; case "~/entityset/key/property/dynamicproperty": case "~/entityset/key/cast/property/dynamicproperty": case "~/singleton/property/dynamicproperty": case "~/singleton/cast/property/dynamicproperty": dynamicPropertSegment = odataPath.Segments.Last() as DynamicPathSegment; if (dynamicPropertSegment == null) { return(null); } PropertySegment propertyAccessSegment = odataPath.Segments[odataPath.Segments.Count - 2] as PropertySegment; if (propertyAccessSegment == null) { return(null); } EdmComplexType complexType = propertyAccessSegment.Property.Type.Definition as EdmComplexType; if (complexType == null) { return(null); } if (controllerContext.Request.Method == HttpMethod.Get) { string actionNamePrefix = String.Format(CultureInfo.InvariantCulture, "Get{0}", _actionName); actionName = actionMap.FindMatchingAction(actionNamePrefix + "From" + propertyAccessSegment.Property.Name); } break; default: break; } if (actionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { KeySegment keyValueSegment = (KeySegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment); } controllerContext.RouteData.Values[ODataRouteConstants.DynamicProperty] = dynamicPropertSegment.Identifier; var key = ODataParameterValue.ParameterValuePrefix + ODataRouteConstants.DynamicProperty; var value = new ODataParameterValue(dynamicPropertSegment.Identifier, EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))); controllerContext.RouteData.Values[key] = value; controllerContext.Request.ODataProperties().RoutingConventionsStore[key] = value; return(actionName); } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } if (controllerContext.Request.Method == HttpMethod.Get) { string actionName = null; BoundFunctionPathSegment function = null; switch (odataPath.PathTemplate) { case "~/entityset/key/cast/function": case "~/entityset/key/function": function = odataPath.Segments.Last() as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: false); if (actionName != null) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } break; case "~/entityset/key/cast/function/$count": case "~/entityset/key/function/$count": function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: false); if (actionName != null) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } break; case "~/entityset/cast/function": case "~/entityset/function": function = odataPath.Segments.Last() as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: true); break; case "~/entityset/cast/function/$count": case "~/entityset/function/$count": function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: true); break; case "~/singleton/function": case "~/singleton/cast/function": function = odataPath.Segments.Last() as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: false); break; case "~/singleton/function/$count": case "~/singleton/cast/function/$count": function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment; actionName = GetFunction(function).SelectAction(actionMap, isCollection: false); break; } if (actionName != null) { controllerContext.AddFunctionParameterToRouteData(function); return(actionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } HttpMethod requestMethod = controllerContext.Request.Method; IHttpRouteData routeData = controllerContext.RouteData; if (!IsSupportedRequestMethod(requestMethod)) { return(null); } if (odataPath.PathTemplate == "~/entityset/key/navigation/$ref" || odataPath.PathTemplate == "~/entityset/key/cast/navigation/$ref" || odataPath.PathTemplate == "~/singleton/navigation/$ref" || odataPath.PathTemplate == "~/singleton/cast/navigation/$ref") { NavigationPropertyLinkSegment navigationLinkSegment = (NavigationPropertyLinkSegment)odataPath.Segments.Last(); IEdmNavigationProperty navigationProperty = navigationLinkSegment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringEntityType(); string refActionName = FindRefActionName(actionMap, navigationProperty, declaringType, requestMethod); if (refActionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { controllerContext.AddKeyValueToRouteData((KeySegment)odataPath.Segments[1]); } routeData.Values[ODataRouteConstants.NavigationProperty] = navigationLinkSegment.NavigationProperty.Name; return(refActionName); } } else if ((requestMethod == HttpMethod.Delete) && ( odataPath.PathTemplate == "~/entityset/key/navigation/key/$ref" || odataPath.PathTemplate == "~/entityset/key/cast/navigation/key/$ref" || odataPath.PathTemplate == "~/singleton/navigation/key/$ref" || odataPath.PathTemplate == "~/singleton/cast/navigation/key/$ref")) { // the second key segment is the last segment in the path. // So the previous of last segment is the navigation property link segment. NavigationPropertyLinkSegment navigationLinkSegment = (NavigationPropertyLinkSegment)odataPath.Segments[odataPath.Segments.Count - 2]; IEdmNavigationProperty navigationProperty = navigationLinkSegment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringEntityType(); string refActionName = FindRefActionName(actionMap, navigationProperty, declaringType, requestMethod); if (refActionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { controllerContext.AddKeyValueToRouteData((KeySegment)odataPath.Segments[1]); } routeData.Values[ODataRouteConstants.NavigationProperty] = navigationLinkSegment.NavigationProperty.Name; controllerContext.AddKeyValueToRouteData((KeySegment)odataPath.Segments.Last(e => e is KeySegment), ODataRouteConstants.RelatedKey); return(refActionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } string prefix; TypeSegment cast; IEdmProperty property = GetProperty(odataPath, controllerContext.Request.Method, out prefix, out cast); IEdmEntityType declaringType = property == null ? null : property.DeclaringType as IEdmEntityType; if (declaringType != null) { string actionName; if (cast == null) { actionName = actionMap.FindMatchingAction( prefix + property.Name + "From" + declaringType.Name, prefix + property.Name); } else { IEdmComplexType typeCast; if (cast.EdmType.TypeKind == EdmTypeKind.Collection) { typeCast = ((IEdmCollectionType)cast.EdmType).ElementType.AsComplex().ComplexDefinition(); } else { typeCast = (IEdmComplexType)cast.EdmType; } // for example: GetCityOfSubAddressFromVipCustomer or GetCityOfSubAddress actionName = actionMap.FindMatchingAction( prefix + property.Name + "Of" + typeCast.Name + "From" + declaringType.Name, prefix + property.Name + "Of" + typeCast.Name); } if (actionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { KeySegment keyValueSegment = (KeySegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment); } return(actionName); } } return(null); }
/// <inheritdoc/> public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } HttpMethod requestMethod = controllerContext.Request.Method; IHttpRouteData routeData = controllerContext.RouteData; if (!IsSupportedRequestMethod(requestMethod)) { return(null); } if (odataPath.PathTemplate == "~/entityset/key/navigation/$ref" || odataPath.PathTemplate == "~/entityset/key/cast/navigation/$ref" || odataPath.PathTemplate == "~/singleton/navigation/$ref" || odataPath.PathTemplate == "~/singleton/cast/navigation/$ref") { NavigationPathSegment navigationSegment = (NavigationPathSegment)odataPath.Segments[odataPath.Segments.Count - 2]; IEdmNavigationProperty navigationProperty = navigationSegment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringEntityType(); string refActionName = FindRefActionName(actionMap, navigationProperty, declaringType, requestMethod); if (refActionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } routeData.Values[ODataRouteConstants.NavigationProperty] = navigationSegment.NavigationProperty.Name; return(refActionName); } } else if ((requestMethod == HttpMethod.Delete) && ( odataPath.PathTemplate == "~/entityset/key/navigation/key/$ref" || odataPath.PathTemplate == "~/entityset/key/cast/navigation/key/$ref" || odataPath.PathTemplate == "~/singleton/navigation/key/$ref" || odataPath.PathTemplate == "~/singleton/cast/navigation/key/$ref")) { NavigationPathSegment navigationSegment = (NavigationPathSegment)odataPath.Segments[odataPath.Segments.Count - 3]; IEdmNavigationProperty navigationProperty = navigationSegment.NavigationProperty; IEdmEntityType declaringType = navigationProperty.DeclaringEntityType(); string refActionName = FindRefActionName(actionMap, navigationProperty, declaringType, requestMethod); if (refActionName != null) { if (odataPath.PathTemplate.StartsWith("~/entityset/key", StringComparison.Ordinal)) { EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First(); IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType(); KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1]; controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key); } routeData.Values[ODataRouteConstants.NavigationProperty] = navigationSegment.NavigationProperty.Name; KeyValuePathSegment relatedKeySegment = odataPath.Segments.Last(e => e is KeyValuePathSegment) as KeyValuePathSegment; IEdmEntityType navEntityType = navigationProperty.Type.AsCollection().ElementType().AsEntity().EntityDefinition(); controllerContext.AddKeyValueToRouteData(relatedKeySegment, navEntityType, ODataRouteConstants.RelatedKey); return(refActionName); } } return(null); }