OData / OData/AspNetCoreOData

OData actions with parameters not registering without ODataActionParameters as another parameter on the controller action

Open
#426 9 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 12, 2022.

investigated
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Hi there,

Using:
.NET 6
OData 8.0.5

Unless I am missing something, I am unable to get actions or functions with parameters to register properly unless I add an extra parameter to the controller action for ODataActionParameters.

To repro, clone the repo below and run:
https://github.com/joshcomley/ODataActionBug

For reference here is the EdmModel code:

public static IEdmModel GetEdmModel()
{
    if (_model != null)
    {
        return _model;
    }

    ODataConventionModelBuilder builder = new();
    
    var users = builder.EntitySet<User>("Users");

    // Works
    var hi = users.EntityType.Collection.Action(nameof(UsersController.Hi));
    hi.Returns<Hello>();

    // Doesn't work
    var hiSimpleFunction = users.EntityType.Collection.Function(nameof(UsersController.HiSimpleFunction));
    hiSimpleFunction.Returns<Hello>();
    hiSimpleFunction.Parameter<string>("name");

    // Doesn't work
    var hiSimple = users.EntityType.Collection.Action(nameof(UsersController.HiSimple));
    hiSimple.Returns<Hello>();
    hiSimple.Parameter<string>("name");

    // Doesn't work
    var hello = users.EntityType.Collection.Action(nameof(UsersController.Hello));
    hello.Returns<Hello>();
    hello.Parameter<SayHello>("request");

    // Doesn't work
    var goodbye = users.EntityType.Action(nameof(UsersController.Hello));
    goodbye.Returns<Hello>();
    goodbye.Parameter<SayHello>("request");

    return _model = builder.GetEdmModel();
}

And one of the actions that isn't working, for example:

[HttpPost]
public IActionResult HiSimpleFunction(string name)
{
    return Ok(
        new Hello
        {
            Message = $"Hi {name}!"
        }
    );
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.