/// <inheritdoc /> public override ODataPathSegment Translate(ODataTemplateTranslateContext context) { if (context == null) { throw Error.ArgumentNull(nameof(context)); } // If the function has no parameter, we don't need to do anything and just return an operation segment. if (ParameterMappings.Count == 0) { return(new OperationSegment(Function, NavigationSource as IEdmEntitySetBase)); } if (!SegmentTemplateHelpers.TryParseRouteKey(context.RouteValues, context.UpdatedValues, ParameterMappings)) { return(null); } IList <OperationSegmentParameter> parameters = SegmentTemplateHelpers.Match(context, Function, ParameterMappings); if (parameters == null) { return(null); } return(new OperationSegment(Function, parameters, NavigationSource as IEdmEntitySetBase)); }
/// <inheritdoc /> public override bool TryTranslate(ODataTemplateTranslateContext context) { if (context == null) { throw Error.ArgumentNull(nameof(context)); } // If the function has no parameter, we don't need to do anything and just return an operation import segment. if (ParameterMappings.Count == 0) { context.Segments.Add(new OperationImportSegment(FunctionImport, NavigationSource as IEdmEntitySetBase)); return(true); } if (HasOptionalMissing()) { // If this function template has the optional parameter missing, // for example: ~/GetSalary(min={min},max={max}), without ave={ave} // We should avoid this template matching with "~/GetSalary(min=1,max=2,ave=3)" // In this request, the comming route data has: // min = 1 // max = 2,ave=3 // so, let's combine the route data together and separate them using "," again. if (!SegmentTemplateHelpers.IsMatchParameters(context.RouteValues, ParameterMappings)) { return(false); } } IList <OperationSegmentParameter> parameters = SegmentTemplateHelpers.Match(context, FunctionImport.Function, ParameterMappings); if (parameters == null) { return(false); } context.Segments.Add(new OperationImportSegment(FunctionImport, NavigationSource as IEdmEntitySetBase, parameters)); return(true); }