OData / OData/AspNetCoreOData

Odata 8.0.6 not working for get request with a key value

Open
#451 16 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 20, 2022.

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

Description

So I recently upgraded to odata version 8.0.6 from version 7. In the new version we don't have the ODataRoutePrefixAttribute and ODataRouteAttribute. So i was using [Route] to map to controller.

[Authorize]
[Route("v1/students")]
public class StudentController : ODataController
{
    [HttpGet("({key)")]
    [EnableQuery]
    public async Task<Student> Get([FromODataUri] long key)
    {
        return await _studentRepository.GetStudentByIdAsync(key);
    }

}
public static IEdmModel GetEdmModel()
 { 
  ODataModelBuilder builder = new ODataConventionModelBuilder(); 
  builder.EntitySet<Student>("Students"); 
  return builder.GetEdmModel(); 
 }

When i am hitting url with https://localhost:5001/v1/student(2) it is working fine because it is convention odata routing but when i am doing attribute based routing and hit url https://localhost:5001/v1/students(2) it give me error 404 not found, when i am doing https://localhost:5001/v1/students/(2) it is giving response. But this action method is non odata endpoint. I am not understanding why this issue is happening.

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.