1
votes

I have web api with OData controller. Models is

public class UserDto
{
   public int UserDtoId {get;set;}
   public string Name {get;set;}
}

in controller I have two method

[EnableQuery]
public IQueryable<UserDto> Get();

[EnableQuery]
public SingleResult<UserDto> GetUser([FromODataUri] int key);

OData config is:

      ODataModelBuilder builder = new ODataConventionModelBuilder();
   builder.EntitySet<UserDto>("Users").EntityType.HasKey(e=>e.UserDtoId).Name = "User";
  config.MapODataServiceRoute(
    routeName: "ODataRoute",
    routePrefix: "odata",
    model: builder.GetEdmModel());

when I try invoke odata/Users(123), the odata try to invoke first get not a get with a key and return me all record from table. When I comment out first get method there is none GET method for this URI access at all. Where I make a mistake?

I try to make [ODataRoute] its doesnt change nothing.

1

1 Answers

0
votes

In your code, your two functions are Get() and GetUser(int key) They should both be 'Get'

Also not sure if it matters, but for the Get(int) one, if it still doesnt work, try changing SingleResult<UserDto> to just UserDto