При анализе URI OData с несвязанными действиями и параметрами генерируется следующее исключение: The request URI is not valid. The segment 'TestAction' cannot include key predicates, however it may end with empty parenthesis
. Приведенный ниже код воспроизводит исключение:Использование несвязанного действия с параметрами в OData
var builder = new ODataConventionModelBuilder
{
Namespace = "Test",
ContainerName = "Test"
};
var action = builder.Action("TestAction").Returns<long>();
action.Parameter<int?>("x");
action.Parameter<int?>("y");
var model = builder.GetEdmModel();
var parser = new ODataUriParser(model, new Uri("TestAction(x=1,y=2)", UriKind.Relative));
var path = parser.ParsePath();
Я исследовал Microsoft.OData.Core
исходные коды и нашел это в FunctionOverloadResolver
классе:
try
{
if (parameterNames.Count > 0)
{
// In this case we have to return a function so filter out actions because the number of parameters > 0.
candidateMatchingOperationImports = resolver.ResolveOperationImports(model, identifier).RemoveActionImports(out foundActionImportsWhenLookingForFunctions).FilterFunctionsByParameterNames(parameterNames, resolver.EnableCaseInsensitive).Cast<IEdmOperationImport>().ToList();
}
else
{
candidateMatchingOperationImports = resolver.ResolveOperationImports(model, identifier).ToList();
}
}
catch (Exception exc)
{
if (!ExceptionUtils.IsCatchableExceptionType(exc))
{
throw;
}
throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_FoundInvalidOperationImport(identifier), exc);
}
if (foundActionImportsWhenLookingForFunctions.Count > 0)
{
throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
}
Почему класс распознаватель нужно отфильтровать действия, когда операция имеет параметры?