Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conventional routing cannot identify the endpoint for action to query property without the key #1397

Open
xuzhg opened this issue Jan 23, 2025 · 0 comments · May be fixed by #1398
Open

Conventional routing cannot identify the endpoint for action to query property without the key #1397

xuzhg opened this issue Jan 23, 2025 · 0 comments · May be fixed by #1398
Labels
bug Something isn't working

Comments

@xuzhg
Copy link
Member

xuzhg commented Jan 23, 2025

Assemblies affected
Which assemblies and versions are known to be affected e.g. ASP.NET Core OData 8.x

Describe the bug
A clear and concise description of what the bug is.

Reproduce steps
The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

Data Model

public class CustomerService
{
    [Contained]
    public List<StoreCustomer> customers { get; set; } = new List<StoreCustomer>();
}

public class StoreCustomer
{
    public String id { get; set; }
}

Then we build the Edm model using a singleton as

modelBuilder.Singleton<CustomerService>("CustomerService");

The controller has the following:

    public class CustomerServiceController : ODataController
    {
        [EnableQuery]
        [HttpGet]
        public ActionResult<IEnumerable<StoreCustomer>> GetCustomers()
        {
            return Ok(CustomersController.customers);
        }
    }

Expected behavior
The conventional routing should identify 'GetCustomers' and build endpoints for it.

Actual behavior
There's no endpoint generated for this action.

Additional context
The root cause is that:

In the NavigationRoutingConvention, there's a logic as below:
https://github.com/OData/AspNetCoreOData/blob/main/src/Microsoft.AspNetCore.OData/Routing/Conventions/NavigationRoutingConvention.cs#L68-L74

bool hasKeyParameter = action.HasODataKeyParameter(entityType, context.Options?.RouteOptions?.EnablePropertyNameCaseInsensitive ?? false);
        if (!(context.Singleton != null ^ hasKeyParameter))
        {
            // Singleton, doesn't allow to query property with key
            // entityset, doesn't allow for non-key to query property
            return false;
        }

However, 'hasKeyParameter' should have 'false' but it has the 'true'.

HasODataKeyParameter has an issue to treat the entity type without key.

@xuzhg xuzhg added the bug Something isn't working label Jan 23, 2025
xuzhg added a commit that referenced this issue Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant