10

I have two Odata action methods defined. The one with parameter gets invoked while the other without parameter doesnt get invoked and throws error No routing convention was found to select an action for the OData path with template '~/entityset'.

Here is the code of my action methods

[EnableQuery]
    public IQueryable<User> GetUser()
    {
        return db.Users;
    }

    // GET: odata/User(5)
    [EnableQuery]
    public SingleResult<User> GetUser([FromODataUri] int key)
    {
        return SingleResult.Create(db.Users.Where(user => user.Id == key));
    }

The query that I am using are as follows

http://bureauservice/api/odata/UserOdata - Doesnt work
http://bureauservice/api/odata/UserOdata(1) - works

Could someone tell me why the first link doesnt work.

user3751248
  • 303
  • 4
  • 8
  • 18

3 Answers3

14

Please change the name of the method which returns entityset to "Get[EntitySetName]" or "Get".

Change from

public IQueryable<User> GetUser()

To

public IQueryable<User> GetUserOdata()

Or

public IQueryable<User> Get()
Feng Zhao
  • 2,977
  • 1
  • 14
  • 20
4

Set the name of the first action as GetUsers (plural) because you are getting the whole collection of users while in the second you are asking for a single user.

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
0

You may want to add the parenthesis to the first URL:

http://bureauservice/api/odata/UserOdata() 

If you are just starting to proactise odata, then Odata v4 is good start point, as it is an OASIS standard, but v3 is not.

Here is the v4 version Function sample: https://github.com/OData/ODataSamples/tree/master/WebApiCore/ODataFunctionSample.

Jafin
  • 4,153
  • 1
  • 40
  • 52
Tan Jinfu
  • 3,327
  • 1
  • 19
  • 20