Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No routing convention was found to select an action for the OData path with template '~/entityset'

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.

like image 654
user3751248 Avatar asked Jul 14 '14 15:07

user3751248


2 Answers

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()
like image 153
Feng Zhao Avatar answered Oct 24 '22 07:10

Feng Zhao


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.

like image 34
Andres Urena Avatar answered Oct 24 '22 06:10

Andres Urena