// GET api/Product/5
public Product GET([FromODataUri]int id)
{
Product product = db.Products.Find(id);
if (product == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return product;
}
this above of getting entity with ID is never called with my url :
http://localhost:53208/odata/Product(1)
even with default settings in odata route this is not called.
first i was trying with this odata route settings:
config.Routes.MapODataRoute("ODataRoute", "odata", GetEdmModel());
remember my simple Get with queries is working fine. but this is the only thing which is working, and PUT method is working. other all are not working. this is view of controller. I have tried for about a day.. please help.
public class ProductController : ODataController
{
private OfferAssistantDbContext db = new OfferAssistantDbContext();
// GET api/Product
public IQueryable<Product> GET()
{
return db.Products.AsQueryable<Product>();
}
// GET api/Product/5
public Product GET([FromODataUri]int id)
{
Product product = db.Products.Find(id);
if (product == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return product;
}
Web API OData is particular with parameter names. The parameter name should be key
instead of id
i.e.
public Product GET([FromODataUri]int key)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With