1

単純な Asp.net mvc4 プロジェクトの前に、Odata Web API プロジェクトをセットアップするのに約 2 日を費やしました。

しかし、まだCRUD操作でさえ成功していません。それはこう言います:

<m:message xml:lang="en-US">
No HTTP resource was found that matches the request URI 'http://localhost:53208/odata/Product'.
</m:message>
<m:innererror>
<m:message>
No action was found on the controller 'Product' that matches the request.
</m:message>
<m:type/>
<m:stacktrace/>
</m:innererror>

これは、コントローラーに到達してもアクションが見つからないか、ルーティング設定に問題があることを意味します。

私は WebApiConfig に以下を持っています:

config.Routes.MapODataRoute("OData","odata",GetEdmModel());

私の getEdmModel メソッド:

private static IEdmModel GetEdmModel()
    {
        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Product>("Product");
        builder.EntitySet<OfferedProduct>("OfferedProduct");


        IEdmModel model = builder.GetEdmModel();

        return model;
    }

私のコントローラーは次のようなものです:

public class ProductController : EntitySetController<Product,int>
{
    private OfferAssistantDbContext db = new OfferAssistantDbContext();
    List<Product> Products = new OfferAssistantDbContext().Products.ToList();
    // GET api/Product
    [Queryable(PageSize = 10)]
    public override IQueryable<Product> Get()
    {
        return Products.AsQueryable();
    }

    // GET api/Product/5
    public Product GetProduct([FromODataUri] int id)
    {
        return Products[id];
    }
    /// and so on... but for this time lets work only on GET operation 

これをブラウザに書き込むと、次のようになります。

http://localhost:53208/odata/Product

それは私が上に示したエラーを言います..

どこに問題があるのか​​教えてください。

4

1 に答える 1

1

コントローラーは ODataController から継承する必要があると思います:

public class ProductController : ODataController
于 2015-01-08T16:17:43.870 に答える