不能在.net Odata Implementation中通过id选择实体

ahm*_*och 8 .net api rest odata asp.net-mvc-4

// 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;
    }
Run Code Online (Sandbox Code Playgroud)

从来没有使用我的网址调用以上获取具有ID的实体:

http://localhost:53208/odata/Product(1)
Run Code Online (Sandbox Code Playgroud)

即使使用odata路线中的默认设置,也不会调用它.

首先我尝试使用这种odata路线设置:

 config.Routes.MapODataRoute("ODataRoute", "odata", GetEdmModel());
Run Code Online (Sandbox Code Playgroud)

记住我的简单Get with queries工作正常.但这是唯一有效的方法,PUT方法正在发挥作用.其他都没有用.这是控制器的视图.我已经试了大约一天..请帮忙.

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;
    }
Run Code Online (Sandbox Code Playgroud)

Rag*_*nti 12

Web API OData特别适用于参数名称.参数名称应该是ie key而不是idie

public Product GET([FromODataUri]int key)
{
}
Run Code Online (Sandbox Code Playgroud)